1

Just started learning ggplot and I'm trying to change my groups to show different geom lines (i.e. one dashed, one smooth/straight line). Below is a mock of my code and how my plot currently looks:

 ggplot(longdat,aes(visitnum,score, colour=Groups)) +
                        stat_summary(fun.y="mean", geom="line", size=.25 ) + stat_summary(fun.y="mean", geom="point") +
                        scale_x_continuous(name="Timepoints",breaks=c(0,4,12),labels=c("Time 1","Time 4","Time 12")) +
                        scale_y_continuous(name="Levels") +
                        theme(axis.text.x=element_text(angle=45,hjust=1))
                      
                      

enter image description here

I want to change the plot to black and white. However before I do that, I would need to change the lines so I can clearly see the difference between the 2 groups in b&w.

Below is my current code but it seems to re-connect the timepoints in a weird way:

     ggplot(longdat,aes(visitnum,score, group=Groups)) +
                        geom_line(aes(linetype=Groups)) +
                        geom_point() +
                        stat_summary(fun.y="mean", size=.25 ) + stat_summary(fun.y="mean") +
                        scale_x_continuous(name="Timepoints",breaks=c(0,4,12),labels=c("Time 1","Time 4","Time 12")) +
                        scale_y_continuous(name="Levels") +
                        theme(axis.text.x=element_text(angle=45,hjust=1))

enter image description here

I've managed to change the group line types (albeit still not as obvious b/w the two groups), but now its connecting the mean scores between the 3 timepoints in a weird way...

Not sure what's causing this, or whether I have to implement the "geom_line" and "geom_point" functions within my "stat_summary" functions?

Any assistance would be appreciated.

Monarch
  • 135
  • 6
  • 3
    Stick with your first code and try `stat_summary(aes(linetype = Groups), fun.y="mean", geom="line", size=.25 )`. – stefan Mar 05 '22 at 17:09
  • Ah perfect! Thanks this definitely worked. Seems like I just had to slot that inside my stat_summary functions. – Monarch Mar 05 '22 at 17:12

0 Answers0