Geom_point(aes(color= Group2, shape = Group1))+ If need be, you can then adjust the legend, e.g with override.aesĭemo Then change the look of this aesthetic with scale functions.First define an aesthetic for your variables (color/fill/shape/linetype/alpha).Unfortunately, your code is not fully reproducible (where is summarySE from? What are sd.x and sd.y)? Here hopefully some more general guidance, translating Camilles spot on comment into code. Geom_polygon(aes(fill = Group2), alpha = 0.2, color = "grey",show.legend = F)+Īes(x = Mean_X, y = Mean_Y, colour = Group2), size = 4)+Īes(x = Mean_X, ymin = Mean_Y-SE_Y, ymax = Mean_Y+SE_Y,Ĭolour = Group2), width = 0.2,show.legend = FALSE)+Īes(y = Mean_Y, xmin = Mean_X-SE_X, xmax = Mean_X+SE_X,Ĭolour = Group2), height = 0.2,show.legend = FALSE)+ĭata= Sum_DF,aes(label=Group2, colour=Group2, x = Mean_X, y = Mean_Y),check_overlap = F, Geom_point(aes(colour = Group2, shape = Group2))+ So, first, you can summarise your dataframe by grouping by "Group1" and "Group2" using group_by function from dplyr package and calculate the mean and SEM using summarise as follow: library(dplyr)Īnd then you can use both dataframes (df and Sum_DF) to plot your various geom by calling inherit.aes = FALSE when you want to call the second dataframe (here I used geom_polygon instead of geom_encircle because you did not specify from which library it was obtained - ggalt - and I did not want to install it): library(ggplot2) in order to indicate to ggplot2 that you are using a different dataframe from the one specified in ggplot(. When you have multiple dataframe to call, you can use the argument inherit.aes = FALSE in geom_. In the current output, the legend only shows factors from GroupA, how can I eide the code to have all legend keys from GroupA, GroupB, GroupC? Guides(colour = "none", shape = "legend")+ Geom_point(data=GroupC,aes(colour=Group2),size=2, alpha=0.3, shape= 0)+ Geom_encircle(data=GroupC, aes(fill = Group2), s_shape = 1, expand = 0,Īlpha = 0.2, color = "black",size=1.5, show.legend = F)+ Geom_point(data=GroupA,aes(shape=Group2), size=2,alpha=0.2)+ Geom_point(data=GroupB,aes(color=Group2), size=3, shape=21, alpha=0.2)+ Geom_text(data=GroupB_SE,aes(label=Group2, colour=Group2),check_overlap = F, Geom_errorbarh(aes(colour=Group2,xmax=X+sd.x, xmin=X-sd.x), alpha=1,size=1.5)+ Geom_point(aes(colour=Group2),size=4, alpha=1)+ GroupB_SE<-merge(GroupB_YSE, GroupB_XSE, by=c("Group2","N")) GroupB_XSE <- summarySE(GroupB, measurevar="X", groupvars=c("Group2")) GroupB_YSE <- summarySE(GroupB, measurevar="Y", groupvars=c("Group2")) GroupC <- dplyr::select(filter(demo, Group1="C"), Group2, X, Y) GroupB <- dplyr::select(filter(demo, Group1="B"), Group2, X, Y) GroupA <- dplyr::select(filter(demo, Group1="A"), Group2, X, Y) I would like to show all three legends.įor example, I have this data set: data('demo') Group1 Group2 Y X I have a multiple plot with three data frame in ggplot2.
0 Comments
Leave a Reply. |