![]() ![]() Ggplot ( dat, aes ( x = xvar, y = yvar, shape = cond )) + geom_point () # Same, but with different shapes Se = FALSE, # Don't add shaded confidence regionįullrange = TRUE ) # Extend regression lines # Extend the regression lines beyond the domain of the data Se = FALSE ) # Don't add shaded confidence region Geom_smooth ( method = lm, # Add linear regression lines Ggplot ( dat, aes ( x = xvar, y = yvar, color = cond )) + geom_point ( shape = 1 ) + scale_colour_hue ( l = 50 ) + # Use a slightly darker palette than normal Geom_linerange(aes(ymin = pred - 1.96 * SE, ymax = pred + 1.Ggplot ( dat, aes ( x = xvar, y = yvar, color = cond )) + geom_point ( shape = 1 ) # Same, but with different colors and add regression lines Geom_linerange(aes(ymin = pred - 1.96 * SE, ymax = pred + 1.96 * SE, linetype = model),įinally, you may want to considered facets: ggplot(df, aes(x = interaction(model, factor(Type)), y = pred, color = factor(id))) + Geom_linerange(aes(ymin = pred - 1.96 * SE, ymax = pred + 1.96 * SE),Īlternatively, you pass an additional aesthetic to geom_linerange to further delineate the model type: ggplot(df, aes(x = interaction(model, factor(Type)), y = pred, color = factor(id))) + ![]() Geom_point(position = position_dodge(width = 0.6), size = 5) + Ggplot(df, aes(x = interaction(model, factor(Type)), y = pred, color = factor(id))) + How about adding first adding some new variables to each dataset and then combining them: newdat$model <- "model1" Any help is much appreciated, as I'm completely stuck. Scale_x_discrete(name="Type", limits=c("1","2"))Ĭode for fig 2 is identical, but without the limits in the last line and with id defined for x-axis in ggplot(aes())Īs I understand it, defining stuff at ggplot() makes that stuff "standard" along the whole graph, and I've tried to remove the common stuff and separately define geom_point and geom_linerange for both newdat and newdat2, but no luck so far. Geom_linerange(aes(ymin=newdat$pred-1.96*SE,ymax=newdat$pred+1.96*SE), position=pd, size=1.5, linetype=1) + Ggplot(newdat,aes(x=Type,y=newdat$pred,colour=id))+ My (hopefully) reproducible (but obviously very bad) code for fig 1: library(ggplot2) And to make things even worse, I need some labels for Type in newdat. The problem is also, that I need to label and organize the resulting figure so that for newdat the x-axis would include a label for "model1" and for newdat2 a label for "model2", or some similar indicator that they are from different models. So the resulting plot would look like fig 1 but with 3 groups of 6 ids. What I would like to accomplish is to plot fig2 to the left/right of fig1 with similar grouping. However, in fig 2 there is no Type, but instead just the 6 ids. What I can do with ggplot, is plot either one, like this:Īs you can see, in fig 1 ids are stacked by Type on the x-axis to form two groups of 6 ids. The ames are: newdatĪs you can see, the second ame doesn't have Type, whereas the first does, and therefore has 2 values for each id. I have 2 ames (that come from separate mixed models) and I'm trying to plot them both into the same graph. ![]() I'm still a newbie with ggplot2 and can't seem to wrap my head around it quite so easily. This must be a FAQ, but I can't find an exactly similar example in the other answers (feel free to close this if you can point a similar Q&A). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |