Seite 1 von 1

Grafiken in ggplot2 so dass Y Achsen exakt übereinander liegen

Verfasst: Fr Aug 25, 2017 11:52 am
von eimichae
Hallo Zusammen.

Wenn ich mit ggplot und der Funktion grid.arrage aus dem package gridExtra mehrere Figures übereinander darstellen möchte, werden sie so angeordent, dass die Zahlenwerte der Y-Achse vertikal bündig sind (BSP Code). Ich möcht aber, dass die Y-Achsen auf der exalten vertikalen Position übereinander liegen und nicht die Zahlen (siehe Abbildung). Gibt es da eine Möglichkeit wie dies erreicht werden kann in R?

Danke für eure Hilfe,
Michi

Code: Alles auswählen

library(gridExtra)
library(ggplot2)


# To prevent that errorbars overlap use position_dodge to move them horizontally
pd <- position_dodge(1)


#IMAGE 5-------------------------------------------
#Create errorbar using 95% se, color =damage
Image5<-ggplot(GossCIBi, aes(x=id, y=Gossypol, colour=id, linetype=id)) +
  #widht= wisker widht, siz=widht of bars
  geom_errorbar(aes(ymin=Gossypol-se, ymax=Gossypol+se), width=0, size=1,position=pd, color="black") +
  #bars should be next to each other (not stacked) 
  geom_line(position=pd) +
  #Color for errorbars  
  scale_colour_manual(values=c("white","black","black","white","black","black"))+
  scale_linetype_manual(values=c(1,1,1,1,1,1))+
  #size of points indicateing mean  
  geom_point(aes(x=id, y=Gossypol),position=pd,size=5.6,colour="black")+
  geom_point(aes(x=id, y=Gossypol,shape=id,colour=id),position=pd,size=6)+
  scale_alpha_manual(values=c(1,1,1)) +
  scale_shape_manual(name="Treatment",labels=c("NonC","NonLy","NonJa","BtC","BtLy","BtJa"),values = c(20,16,15,20,16,15)) +
  scale_x_discrete(expand=c(0.1, 1)) +
  ylim(0,24)+
  #Labeling of axes and size of lables and legend
  labs(x="",y="")+
  scale_x_discrete(labels = c("C","Lygus","JA","C","Lygus","JA"))+
  theme_bw()+
  theme(axis.text=element_text(size=17),
        axis.title=element_text(size=17),axis.text.x=element_text(angle=70,hjust=1))+
  theme(legend.position="none")
Image5



#IMAGE 8-------------------------------------------
#Create errorbar using 95% se, color =damage
Image8<-ggplot(GossCIPh, aes(x=id, y=Gossypol, colour=id, linetype=id)) +
  #widht= wisker widht, siz=widht of bars
  geom_errorbar(aes(ymin=Gossypol-se, ymax=Gossypol+se), width=0, size=1,position=pd, color="black") +
  #bars should be next to each other (not stacked) 
  geom_line(position=pd) +
  #Color for errorbars  
  scale_colour_manual(values=c("white","black","black","white","black","black"))+
  scale_linetype_manual(values=c(1,1,1,1,1,1))+
  #size of points indicateing mean  
  geom_point(aes(x=id, y=Gossypol),position=pd,size=5.6,colour="black")+
  geom_point(aes(x=id, y=Gossypol,shape=id,colour=id),position=pd,size=6)+
  scale_alpha_manual(values=c(1,1,1)) +
  scale_shape_manual(name="Treatment",labels=c("NonC","NonLy","NonJa","BtC","BtLy","BtJa"),values = c(20,16,15,20,16,15)) +
  scale_x_discrete(expand=c(0.1, 1)) +
  ylim(0,10000)+
  #Labeling of axes and size of lables and legend
  labs(x="",y="")+
  scale_x_discrete(labels = c("C","Lygus","JA","C","Lygus","JA"))+
  theme_bw()+
  theme(axis.text=element_text(size=17),
        axis.title=element_text(size=17),axis.text.x=element_text(angle=70,hjust=1))+
  theme(legend.position="none")
Image8

# GRID----------------------------------------

grid.arrange(Image5,Image8,ncol=1)

Re: Grafiken in ggplot2 so dass Y Achsen exakt übereinander liegen

Verfasst: Fr Aug 25, 2017 3:24 pm
von EDi
Elegante Lösung: mit facet_grid arbeiten.
Dazu muss dein Datensatz nur ins lange Format, siehe zB tidyr::gather ().

Re: Grafiken in ggplot2 so dass Y Achsen exakt übereinander liegen

Verfasst: Fr Aug 25, 2017 5:22 pm
von eimichae
Hoi EDi,

Vielen Dank,

Facet_grid ist super! Kannte ich nicht.

Ich möchte meine Daten gerne als mean +/- standard error darstellen (wie in der ersten Abbildung).
Ist dies auch mit der facet_grid option möglich?
Ich nehem an ich muss mit "geom_errorbar" arbeiten. Leider habe ich es trozt langem pröbeln nicht hingekriegt (v.a. da mein datanefile nun anders strukturier ist).

Kannst du mir da weiterhelfen?

Sorry und vielen Dank,
Michi

Code: Alles auswählen

#Load packages
library(ggplot2)
library(gridExtra)





#Individual horizontal grids---------------------------------------------


# Divide by levels of "Compund", in the horizontal direction
#basis + facet_grid(. ~ Compound)

#Only dta for Boll exocarp
dtaBo<-subset(dta,Organ=="Bo")
head(dtaBo)


pd <- position_dodge(1)

basis<- ggplot(dtaBo, aes(x=Treatment, y=Concentration, colour=id))+
geom_point(shape=1)
 

Bo<-basis+facet_grid(.~Compound)
Bo
DATEN:
> dput(Bo)
structure(list(data = structure(list(Code = structure(c(196L,
208L, 227L, 251L, 2L, 26L, 50L, 74L, 98L, 122L, 146L, 192L, 200L,
212L, 231L, 255L, 277L, 6L, 30L, 54L, 78L, 102L, 126L, 150L,
235L, 259L, 281L, 10L, 34L, 58L, 82L, 106L, 130L, 154L, 166L,
188L, 204L, 216L, 239L, 263L, 285L, 14L, 38L, 62L, 86L, 110L,
134L, 158L, 170L, 180L, 220L, 243L, 267L, 289L, 18L, 42L, 66L,
90L, 114L, 138L, 224L, 247L, 271L, 293L, 22L, 46L, 70L, 94L,
118L, 142L, 162L, 174L, 184L, 196L, 208L, 227L, 251L, 2L, 26L,
50L, 74L, 98L, 122L, 146L, 192L, 200L, 212L, 231L, 255L, 277L,
6L, 30L, 54L, 78L, 102L, 126L, 150L, 235L, 259L, 281L, 10L, 34L,
58L, 82L, 106L, 130L, 154L, 166L, 188L, 204L, 216L, 239L, 263L,
285L, 14L, 38L, 62L, 86L, 110L, 134L, 158L, 170L, 180L, 220L,
243L, 267L, 289L, 18L, 42L, 66L, 90L, 114L, 138L, 224L, 247L,
271L, 293L, 22L, 46L, 70L, 94L, 118L, 142L, 162L, 174L, 184L,
196L, 208L, 227L, 251L, 2L, 26L, 50L, 74L, 98L, 122L, 146L, 192L,
200L, 212L, 231L, 255L, 277L, 6L, 30L, 54L, 78L, 102L, 126L,
150L, 235L, 259L, 281L, 10L, 34L, 58L, 82L, 106L, 130L, 154L,
166L, 188L, 204L, 216L, 239L, 263L, 285L, 14L, 38L, 62L, 86L,
110L, 134L, 158L, 170L, 180L, 220L, 243L, 267L, 289L, 18L, 42L,
66L, 90L, 114L, 138L, 224L, 247L, 271L, 293L, 22L, 46L, 70L,
94L, 118L, 142L, 162L, 174L, 184L), .Label = c("10BtCBi", "10BtCBo",
"10BtCL", "10BtCPh", "10BtJaBi", "10BtJaBo", "10BtJaL", "10BtJaPh",
"10BtLyBi", "10BtLyBo", "10BtLyL", "10BtLyPh", "10NonCBi", "10NonCBo",
"10NonCL", "10NonCPh", "10NonJaBi", "10NonJaBo", "10NonJaL",
"10NonJaPh", "10NonLyBi", "10NonLyBo", "10NonLyL", "10NonLyPh",
"11BtCBi", "11BtCBo", "11BtCL", "11BtCPh", "11BtJaBi", "11BtJaBo",
"11BtJaL", "11BtJaPh", "11BtLyBi", "11BtLyBo", "11BtLyL", "11BtLyPh",
"11NonCBi", "11NonCBo", "11NonCL", "11NonCPh", "11NonJaBi", "11NonJaBo",
"11NonJaL", "11NonJaPh", "11NonLyBi", "11NonLyBo", "11NonLyL",
"11NonLyPh", "12BtCBi", "12BtCBo", "12BtCL", "12BtCPh", "12BtJaBi",
"12BtJaBo", "12BtJaL", "12BtJaPh", "12BtLyBi", "12BtLyBo", "12BtLyL",
"12BtLyPh", "12NonCBi", "12NonCBo", "12NonCL", "12NonCPh", "12NonJaBi",
"12NonJaBo", "12NonJaL", "12NonJaPh", "12NonLyBi", "12NonLyBo",
"12NonLyL", "12NonLyPh", "13BtCBi", "13BtCBo", "13BtCL", "13BtCPh",
"13BtJaBi", "13BtJaBo", "13BtJaL", "13BtJaPh", "13BtLyBi", "13BtLyBo",
"13BtLyL", "13BtLyPh", "13NonCBi", "13NonCBo", "13NonCL", "13NonCPh",
"13NonJaBi", "13NonJaBo", "13NonJaL", "13NonJaPh", "13NonLyBi",
"13NonLyBo", "13NonLyL", "13NonLyPh", "14BtCBi", "14BtCBo", "14BtCL",
"14BtCPh", "14BtJaBi", "14BtJaBo", "14BtJaL", "14BtJaPh", "14BtLyBi",
"14BtLyBo", "14BtLyL", "14BtLyPh", "14NonCBi", "14NonCBo", "14NonCL",
"14NonCPh", "14NonJaBi", "14NonJaBo", "14NonJaL", "14NonJaPh",
"14NonLyBi", "14NonLyBo", "14NonLyL", "14NonLyPh", "15BtCBi",
"15BtCBo", "15BtCL", "15BtCPh", "15BtJaBi", "15BtJaBo", "15BtJaL",
"15BtJaPh", "15BtLyBi", "15BtLyBo", "15BtLyL", "15BtLyPh", "15NonCBi",
"15NonCBo", "15NonCL", "15NonCPh", "15NonJaBi", "15NonJaBo",
"15NonJaL", "15NonJaPh", "15NonLyBi", "15NonLyBo", "15NonLyL",
"15NonLyPh", "16BtCBi", "16BtCBo", "16BtCL", "16BtCPh", "16BtJaBi",
"16BtJaBo", "16BtJaL", "16BtJaPh", "16BtLyBi", "16BtLyBo", "16BtLyL",
"16BtLyPh", "16NonCBi", "16NonCBo", "16NonCL", "16NonCPh", "16NonLyBi",
"16NonLyBo", "16NonLyL", "16NonLyPh", "17BtLyBi", "17BtLyBo",
"17BtLyL", "17BtLyPh", "17NonCBi", "17NonCBo", "17NonCL", "17NonCPh",
"17NonLyBi", "17NonLyBo", "17NonLyL", "17NonLyPh", "18BtLyL",
"18BtLyPh", "18NonCBi", "18NonCBo", "18NonCL", "18NonCPh", "18NonLyBi",
"18NonLyBo", "18NonLyL", "18NonLyPh", "19BtLyBi", "19BtLyBo",
"19BtLyL", "19BtLyPh", "4BtJaBi", "4BtJaBo", "4BtJaL", "4BtJaPh",
"5BtCBi", "5BtCBo", "5BtCL", "5BtCPh", "5BtJaBi", "5BtJaBo",
"5BtJaL", "5BtJaPh", "5NonCBi", "5NonCBo", "5NonCL", "5NonCPh",
"6BtCBi", "6BtCBo", "6BtCL", "6BtCPh", "6BtJaBi", "6BtJaBo",
"6BtJaL", "6BtJaPh", "6NonCBi", "6NonCBo", "6NonCL", "6NonCPh",
"6NonJaBi", "6NonJaBo", "6NonJaL", "6NonJaPh", "6NonLyBi", "6NonLyBo",
"6NonLyL", "7BtCBi", "7BtCBo", "7BtCL", "7BtCPh", "7BtJaBi",
"7BtJaBo", "7BtJaL", "7BtJaPh", "7BtLyBi", "7BtLyBo", "7BtLyL",
"7BtLyPh", "7NonCBi", "7NonCBo", "7NonCL", "7NonCPh", "7NonJaBi",
"7NonJaBo", "7NonJaL", "7NonJaPh", "7NonLyBi", "7NonLyBo", "7NonLyL",
"7NonLyPh", "8BtCBi", "8BtCBo", "8BtCL", "8BtCPh", "8BtJaBi",
"8BtJaBo", "8BtJaL", "8BtJaPh", "8BtLyBi", "8BtLyBo", "8BtLyL",
"8BtLyPh", "8NonCBi", "8NonCBo", "8NonCL", "8NonCPh", "8NonJaBi",
"8NonJaBo", "8NonJaL", "8NonJaPh", "8NonLyBi", "8NonLyBo", "8NonLyL",
"8NonLyPh", "9BtCL", "9BtCPh", "9BtJaBi", "9BtJaBo", "9BtJaL",
"9BtJaPh", "9BtLyBi", "9BtLyBo", "9BtLyL", "9BtLyPh", "9NonCBi",
"9NonCBo", "9NonCL", "9NonCPh", "9NonJaBi", "9NonJaBo", "9NonJaL",
"9NonJaPh", "9NonLyBi", "9NonLyBo", "9NonLyL", "9NonLyPh"), class = "factor"),
Plant = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1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, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Bi", "Bo", "L",
"Ph"), class = "factor"), Concentration = c(3935.689611,
8060.664482, 2281.465638, 5719.008164, 1611.38625, 2132.34965,
2187.676493, 3039.428884, 3993.777964, 3502.229882, 2020.688647,
3213.686322, 7028.61464, 4770.675972, 3035.168014, 8642.248563,
2946.398279, 3289.781609, 5032.477756, 5440.887547, 2478.323599,
4815.163835, 2539.407887, 5918.999001, 10510.90724, 808.6116301,
440.4003209, 2785.149946, 1071.478333, 1217.490013, 1658.539035,
2982.333191, 7165.943452, 10673.8556, 1110.980146, 2829.680288,
6216.189097, 9180.609844, 8087.030956, 3332.545477, 5931.814446,
4503.450807, 3431.927347, 4062.550942, 6430.964819, 5283.631556,
2082.162727, 3368.106731, 6401.40136, 8167.555039, 9527.18461,
8608.698693, 1830.015539, 2732.112282, 1598.250224, 4720.255449,
5491.619216, 1529.727368, 6519.487409, 3254.100484, 6267.562033,
4629.837673, 1918.878122, 2336.323956, 5424.518369, 7298.482594,
4361.15214, 4334.997413, 2482.474963, 1895.896192, 4671.292119,
4178.360499, 2405.682441, 1284.019432, 1674.442517, 799.9335287,
932.7571661, 370.4559106, 846.703517, 549.9248616, 789.6151587,
594.8705974, 859.3815222, 575.8687616, 1037.544745, 2219.235939,
1041.785201, 1011.382482, 2699.318068, 1634.197557, 1479.435513,
1177.141188, 1227.704602, 1025.624231, 2189.548351, 441.3633148,
1156.550535, 2962.96865, 2024.153977, 257.149995, 232.2616623,
557.4817054, 668.819419, 380.0787558, 845.8719866, 1500.349734,
1738.181101, 361.9910606, 943.3662932, 966.5731312, 1482.887607,
1353.306253, 573.0129229, 913.5669096, 973.8458798, 813.0125106,
660.8452053, 1092.07248, 1405.900165, 595.1279591, 625.2362309,
988.8270204, 1038.985553, 1524.816098, 1423.419233, 624.5280615,
869.7016831, 312.8947838, 1273.763844, 1027.384444, 825.7598435,
4.115277933, 1059.328081, 1750.696528, 923.3749983, 600.9614091,
654.9112225, 1260.283849, 1548.494828, 1170.424038, 1240.990804,
532.3258118, 822.2514099, 1183.313986, 1461.781249, 1222.444283,
14067.76262, 16174.79596, 34557.42327, 7277.143883, 41323.14932,
16283.7693, 6743.499014, 16474.24999, 10115.95925, 9815.647653,
5187.755275, 12623.8923, 18489.11626, 8828.023054, 11328.5554,
34530.03424, 31861.36973, 11269.61768, 13304.5835, 10119.05943,
12910.37921, 33654.38033, 14637.60366, 14841.14924, 37934.94733,
37932.95201, 5739.410634, 18033.256, 14133.10165, 17764.12583,
6411.387344, 14182.63911, 32829.99722, 13427.86016, 6818.972296,
19575.58312, 12121.32908, 18113.74662, 20987.82154, 6191.650292,
8210.901366, 17399.26984, 19788.01158, 18843.43296, 22610.80289,
44001.60252, 20845.44286, 20196.82089, 29792.81286, 16574.78057,
24940.5136, 17371.98751, 9858.167505, 4360.133275, 6686.594934,
27294.12446, 29193.94356, 7296.455147, 257.4817124, 20840.23273,
12079.85069, 7498.046956, 10697.94738, 12113.93228, 10718.15824,
1894.082328, 10543.02994, 11770.16173, 8800.497485, 20132.77665,
19958.80261, 31486.64367, 27086.27766), Compound = structure(c(3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Gossypol", "Heliocide",
"Hemigossypolone"), class = "factor")), .Names = c("Code",
"Plant", "id", "Treatment", "Organ", "Concentration", "Compound"
), row.names = c(12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L,
71L, 72L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L,
120L, 121L, 122L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L,
171L, 172L, 173L, 174L, 175L, 176L, 215L, 216L, 217L, 218L, 219L,
220L, 221L, 222L, 223L, 224L, 258L, 259L, 260L, 261L, 262L, 263L,
264L, 265L, 266L, 267L, 268L, 269L, 270L, 307L, 308L, 309L, 310L,
311L, 312L, 313L, 314L, 315L, 316L, 317L, 355L, 356L, 357L, 358L,
359L, 360L, 361L, 362L, 363L, 364L, 365L, 366L, 367L, 406L, 407L,
408L, 409L, 410L, 411L, 412L, 413L, 414L, 415L, 416L, 417L, 458L,
459L, 460L, 461L, 462L, 463L, 464L, 465L, 466L, 467L, 468L, 469L,
470L, 471L, 510L, 511L, 512L, 513L, 514L, 515L, 516L, 517L, 518L,
519L, 553L, 554L, 555L, 556L, 557L, 558L, 559L, 560L, 561L, 562L,
563L, 564L, 565L, 602L, 603L, 604L, 605L, 606L, 607L, 608L, 609L,
610L, 611L, 612L, 650L, 651L, 652L, 653L, 654L, 655L, 656L, 657L,
658L, 659L, 660L, 661L, 662L, 701L, 702L, 703L, 704L, 705L, 706L,
707L, 708L, 709L, 710L, 711L, 712L, 753L, 754L, 755L, 756L, 757L,
758L, 759L, 760L, 761L, 762L, 763L, 764L, 765L, 766L, 805L, 806L,
807L, 808L, 809L, 810L, 811L, 812L, 813L, 814L, 848L, 849L, 850L,
851L, 852L, 853L, 854L, 855L, 856L, 857L, 858L, 859L, 860L), class = "data.frame"),
layers = list(<environment>), scales = <environment>, mapping = structure(list(
x = Treatment, y = Concentration, colour = id), .Names = c("x",
"y", "colour"), class = "uneval"), theme = list(), coordinates = <environment>,
facet = <environment>, plot_env = <environment>, labels = structure(list(
x = "Treatment", y = "Concentration", colour = "id"), .Names = c("x",
"y", "colour"))), .Names = c("data", "layers", "scales",
"mapping", "theme", "coordinates", "facet", "plot_env", "labels"
), class = c("gg", "ggplot")

Re: Grafiken in ggplot2 so dass Y Achsen exakt übereinander liegen

Verfasst: Fr Aug 25, 2017 7:47 pm
von EDi
Der Datendump funktioniert nicht :(

Hab aber nochmal drüber geschaut:

Du musst eigentlich (soweit ich das per Ferndiagnos mit unzureichender Amamnese burteilen kann) nur:

1) Jedem Datensatz eine Indikator-variable hinzufügen welhe angibt welcher Data.frame es ist(geht mit '$')
2) Die zwei Datensätze untereinander packen
4) facet_grid(~indicator_variable> zum ggplot hinzufügen

Re: Grafiken in ggplot2 so dass Y Achsen exakt übereinander liegen

Verfasst: Mo Aug 28, 2017 9:19 am
von eimichae
Hoi EDi,

Ich habe es übers Wochenende an meinen Daten gearbeitet.
Das Problem ist, dass ich meine Daten als Mittelwert +/- SE darstellen möchte und nicht als Rohdatenpunkte.

Normalerweise gehe dabei so vor,dass ich mir
1. die SE Werte von mittels eines Codes berechne
2. mir mit der funktion Subset() aus meinem Datensatz die gewünschten Werte isoliere um davon den SE zu berechnen
3. im ggplot mit der Funktion geom_errorbar meine Daten darstellen.-->Dieses Vorgehen ist aber leider nicht kompatibel mit facet_grid()
Example.jpg
Deinen Vorschlag jedem Datensatz eine Indikator-variable hinzufügen welhe angibt welcher Data.frame es ist(geht mit '$') und davon den Mittelwert +/- SE zu plotten kriege ich nicht hin:(

Kannst du mir ev. mit einem konkreten Beispiel etwas weiter helfen?

Ich hoffe diesmal funktioniert es mit den Daten:

Vielen Dank und sorry für den Aufwand,
Michi

DATEN---------------------------------------
> dput(dta)
structure(list(Code = structure(c(49L, 52L, 57L, 63L, 1L, 7L,
13L, 19L, 25L, 31L, 37L, 48L, 50L, 53L, 58L, 64L, 69L, 2L, 8L,
14L, 20L, 26L, 32L, 38L, 59L, 65L, 70L, 3L, 9L, 15L, 21L, 27L,
33L, 39L, 42L, 47L, 51L, 54L, 60L, 66L, 71L, 4L, 10L, 16L, 22L,
28L, 34L, 40L, 43L, 45L, 55L, 61L, 67L, 72L, 5L, 11L, 17L, 23L,
29L, 35L, 56L, 62L, 68L, 73L, 6L, 12L, 18L, 24L, 30L, 36L, 41L,
44L, 46L, 49L, 52L, 57L, 63L, 1L, 7L, 13L, 19L, 25L, 31L, 37L,
48L, 50L, 53L, 58L, 64L, 69L, 2L, 8L, 14L, 20L, 26L, 32L, 38L,
59L, 65L, 70L, 3L, 9L, 15L, 21L, 27L, 33L, 39L, 42L, 47L, 51L,
54L, 60L, 66L, 71L, 4L, 10L, 16L, 22L, 28L, 34L, 40L, 43L, 45L,
55L, 61L, 67L, 72L, 5L, 11L, 17L, 23L, 29L, 35L, 56L, 62L, 68L,
73L, 6L, 12L, 18L, 24L, 30L, 36L, 41L, 44L, 46L, 49L, 52L, 57L,
63L, 1L, 7L, 13L, 19L, 25L, 31L, 37L, 48L, 50L, 53L, 58L, 64L,
69L, 2L, 8L, 14L, 20L, 26L, 32L, 38L, 59L, 65L, 70L, 3L, 9L,
15L, 21L, 27L, 33L, 39L, 42L, 47L, 51L, 54L, 60L, 66L, 71L, 4L,
10L, 16L, 22L, 28L, 34L, 40L, 43L, 45L, 55L, 61L, 67L, 72L, 5L,
11L, 17L, 23L, 29L, 35L, 56L, 62L, 68L, 73L, 6L, 12L, 18L, 24L,
30L, 36L, 41L, 44L, 46L), .Label = c("10BtCBo", "10BtJaBo", "10BtLyBo",
"10NonCBo", "10NonJaBo", "10NonLyBo", "11BtCBo", "11BtJaBo",
"11BtLyBo", "11NonCBo", "11NonJaBo", "11NonLyBo", "12BtCBo",
"12BtJaBo", "12BtLyBo", "12NonCBo", "12NonJaBo", "12NonLyBo",
"13BtCBo", "13BtJaBo", "13BtLyBo", "13NonCBo", "13NonJaBo", "13NonLyBo",
"14BtCBo", "14BtJaBo", "14BtLyBo", "14NonCBo", "14NonJaBo", "14NonLyBo",
"15BtCBo", "15BtJaBo", "15BtLyBo", "15NonCBo", "15NonJaBo", "15NonLyBo",
"16BtCBo", "16BtJaBo", "16BtLyBo", "16NonCBo", "16NonLyBo", "17BtLyBo",
"17NonCBo", "17NonLyBo", "18NonCBo", "18NonLyBo", "19BtLyBo",
"4BtJaBo", "5BtCBo", "5BtJaBo", "5NonCBo", "6BtCBo", "6BtJaBo",
"6NonCBo", "6NonJaBo", "6NonLyBo", "7BtCBo", "7BtJaBo", "7BtLyBo",
"7NonCBo", "7NonJaBo", "7NonLyBo", "8BtCBo", "8BtJaBo", "8BtLyBo",
"8NonCBo", "8NonJaBo", "8NonLyBo", "9BtJaBo", "9BtLyBo", "9NonCBo",
"9NonJaBo", "9NonLyBo"), class = "factor"), Plant = structure(c(1L,
1L, 1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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Bo", class = "factor"),
Concentration = c(3935.689611, 8060.664482, 2281.465638,
5719.008164, 1611.38625, 2132.34965, 2187.676493, 3039.428884,
3993.777964, 3502.229882, 2020.688647, 3213.686322, 7028.61464,
4770.675972, 3035.168014, 8642.248563, 2946.398279, 3289.781609,
5032.477756, 5440.887547, 2478.323599, 4815.163835, 2539.407887,
5918.999001, 10510.90724, 808.6116301, 440.4003209, 2785.149946,
1071.478333, 1217.490013, 1658.539035, 2982.333191, 7165.943452,
10673.8556, 1110.980146, 2829.680288, 6216.189097, 9180.609844,
8087.030956, 3332.545477, 5931.814446, 4503.450807, 3431.927347,
4062.550942, 6430.964819, 5283.631556, 2082.162727, 3368.106731,
6401.40136, 8167.555039, 9527.18461, 8608.698693, 1830.015539,
2732.112282, 1598.250224, 4720.255449, 5491.619216, 1529.727368,
6519.487409, 3254.100484, 6267.562033, 4629.837673, 1918.878122,
2336.323956, 5424.518369, 7298.482594, 4361.15214, 4334.997413,
2482.474963, 1895.896192, 4671.292119, 4178.360499, 2405.682441,
1284.019432, 1674.442517, 799.9335287, 932.7571661, 370.4559106,
846.703517, 549.9248616, 789.6151587, 594.8705974, 859.3815222,
575.8687616, 1037.544745, 2219.235939, 1041.785201, 1011.382482,
2699.318068, 1634.197557, 1479.435513, 1177.141188, 1227.704602,
1025.624231, 2189.548351, 441.3633148, 1156.550535, 2962.96865,
2024.153977, 257.149995, 232.2616623, 557.4817054, 668.819419,
380.0787558, 845.8719866, 1500.349734, 1738.181101, 361.9910606,
943.3662932, 966.5731312, 1482.887607, 1353.306253, 573.0129229,
913.5669096, 973.8458798, 813.0125106, 660.8452053, 1092.07248,
1405.900165, 595.1279591, 625.2362309, 988.8270204, 1038.985553,
1524.816098, 1423.419233, 624.5280615, 869.7016831, 312.8947838,
1273.763844, 1027.384444, 825.7598435, 4.115277933, 1059.328081,
1750.696528, 923.3749983, 600.9614091, 654.9112225, 1260.283849,
1548.494828, 1170.424038, 1240.990804, 532.3258118, 822.2514099,
1183.313986, 1461.781249, 1222.444283, 14067.76262, 16174.79596,
34557.42327, 7277.143883, 41323.14932, 16283.7693, 6743.499014,
16474.24999, 10115.95925, 9815.647653, 5187.755275, 12623.8923,
18489.11626, 8828.023054, 11328.5554, 34530.03424, 31861.36973,
11269.61768, 13304.5835, 10119.05943, 12910.37921, 33654.38033,
14637.60366, 14841.14924, 37934.94733, 37932.95201, 5739.410634,
18033.256, 14133.10165, 17764.12583, 6411.387344, 14182.63911,
32829.99722, 13427.86016, 6818.972296, 19575.58312, 12121.32908,
18113.74662, 20987.82154, 6191.650292, 8210.901366, 17399.26984,
19788.01158, 18843.43296, 22610.80289, 44001.60252, 20845.44286,
20196.82089, 29792.81286, 16574.78057, 24940.5136, 17371.98751,
9858.167505, 4360.133275, 6686.594934, 27294.12446, 29193.94356,
7296.455147, 257.4817124, 20840.23273, 12079.85069, 7498.046956,
10697.94738, 12113.93228, 10718.15824, 1894.082328, 10543.02994,
11770.16173, 8800.497485, 20132.77665, 19958.80261, 31486.64367,
27086.27766), Compound = structure(c(3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L), .Label = c("Gossypol", "Heliocide", "Hemigossypolone"
), class = "factor")), .Names = c("Code", "Plant", "id",
"Treatment", "Organ", "Concentration", "Compound"), class = "data.frame", row.names = c(NA,
-219L))
>

CODE---------------------------------------

Code: Alles auswählen

#Enter data
dta<-read.csv("dta.csv",sep=";",header=T)
head(dta)


#Load packages
library(ggplot2)
library(gridExtra)




# 1. CI/SE manually computed ------------------------------------------

summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,
                      conf.interval=.95, .drop=TRUE) {
  library(plyr)
  
  # New version of length which can handle NA's: if na.rm==T, don't count them
  length2 <- function (x, na.rm=FALSE) {
    if (na.rm) sum(!is.na(x))
    else       length(x)
  }
  
  # This does the summary. For each group's data frame, return a vector with
  # N, mean, and sd
  datac <- ddply(data, groupvars, .drop=.drop,
                 .fun = function(xx, col) {
                   c(N    = length2(xx[[col]], na.rm=na.rm),
                     mean = mean   (xx[[col]], na.rm=na.rm),
                     sd   = sd     (xx[[col]], na.rm=na.rm)
                   )
                 },
                 measurevar
  )
  
  # Rename the "mean" column    
  datac <- rename(datac, c("mean" = measurevar))
  
  datac$se <- datac$sd / sqrt(datac$N)  # Calculate standard error of the mean
  
  # Confidence interval multiplier for standard error
  # Calculate t-statistic for confidence interval: 
  # e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1
  ciMult <- qt(conf.interval/2 + .5, datac$N-1)
  datac$ci <- datac$se * ciMult
  
  return(datac)
}
#-------------------------------------------------------------------------


# 2. Subsets-----------------------
#Subset Gossypol
GoBo<-subset(dta,Compound=="Gossypol")
SEGoBo<- summarySE(GoBo, measurevar="Concentration", groupvars="Treatment")


#Subset Heliocide
HelBo<-subset(dta,Compound=="Heliocide")
SEHelBo<- summarySE(HelBo, measurevar="Concentration", groupvars="Treatment")


HemBo<-subset(dta,Compound=="Hemigossypolone")
SEHemBo<- summarySE(HemBo, measurevar="Concentration", groupvars="Treatment")




#Individual horizontal grids---------------------------------------------


# Divide by levels of "Compund", in the horizontal direction
#basis + facet_grid(. ~ Compound)


pd <- position_dodge(1)

basis<- ggplot(dta, aes(x=Treatment, y=Concentration, colour=id))+
geom_point(shape=1)
 

Bo<-basis+facet_grid(.~Compound)
Bo

Re: Grafiken in ggplot2 so dass Y Achsen exakt übereinander liegen

Verfasst: Mo Aug 28, 2017 8:48 pm
von EDi
Du brauchst quasi eine Tabelle mit 4 Spalten:

x, facet, color, mean, se

der Rest ist dann straight forward.
Diese Tabelle kannst du mit plyr, dplyr, data.table.
Also Mittelwert + SE pro x, facet und color berechnen.

Re: Grafiken in ggplot2 so dass Y Achsen exakt übereinander liegen

Verfasst: Mo Sep 11, 2017 10:21 am
von eimichae
Bin erst jetzt dazu gekommen.

Habe mit plyr und reshape2 meine Tabelle zusammengestellt so wie du es vorgeschlagen hast. Der Rest war dann wirklich nicht mehr so schwer.

Danke für deine Hilfe.

Michi