1

I came up with a plot using ggplot. I am trying to manually change the shape of my points with scale_shape_manual but it does not work really.

A header of the data I am using:

 visit DF    UPDRS_type            score
  <int> <chr> <chr>                 <dbl>
1     1 A     UPDRSIIItotal_imputed  20.2
2     1 C     UPDRSIIItotal_imputed  26.7
3     1 D     UPDRSIIItotal_imputed  20.7
4     1 B     UPDRSIIItotal_imputed  22.9
5    12 A     UPDRSIIItotal_imputed  21.3
6    18 C     UPDRSIIItotal_imputed  29.2

And also:

unique(meanAcrossVisits$DF)
[1] "A" "C" "D" "B"
unique(meanAcrossVisits$UPDRS_type)
[1] "UPDRSIIItotal_imputed" "UPDRSIIIaxial_imputed" "UPDRSIIIlimb_imputed" `enter code here`

This is the code I am using

ggplot(meanAcrossVisits, aes(x = visit, 
                            y = score, 
                            color = UPDRS_type,
                            shape = DF,
                            group = interaction(UPDRS_type, DF))) +
  
  geom_point(size = 4) +
  scale_shape_manual(values = c(16,17,15,18)) +
  geom_line(size = 1.1) +
  
  scale_x_discrete(name = "visit ( months )",
                   limits=c(1,12,18,24,36),
                   labels=c("BL","12","18","24","36"),
                   expand = c(0.03,0.03)) +
  guides(color = guide_legend(override.aes = list(size = 3))) +
  scale_shape_discrete(name = "Cohorts" ) +
  scale_colour_discrete(name = ("motor symptom")) +
  theme(axis.text=element_text(size=16),
        axis.title=element_text(size=14,face="bold"),
        plot.title = element_text(face = "bold", hjust = 0.5, size = 20)) +
  ggtitle("Change in the motor symptoms")

Which gives this output enter image description here

Does anyone know why ggplot does not recognise the values from: scale_shape_manual(values = c(16,17,15,18))

Limey
  • 10,234
  • 2
  • 12
  • 32
lexmc
  • 11
  • 2
  • 2
    How did you try to add `scale_shape_manual()`? Did you remove `scale_shape_discrete()` prior to that? Is there an error message produced? – teunbrand Jan 07 '22 at 10:22
  • 1
    Remove `scale_shape_discrete` from your code. You could only have one scale per aesthetic. Adding `scale_shape_discrete` after `scale_shape_manual` will override your manual scale. You should get a message which tells you that. – stefan Jan 07 '22 at 10:56
  • 1
    Yes, it worked, thank you. I thought I had to combine the two of them to pass sume arguments such aslegend name. I did not get any warning when ran the code – lexmc Jan 07 '22 at 11:03
  • Great. If you want to change the name you could do so inside `scale_xxx_manual` too or what I prefer do so via `+ labs(shape = "NAME", color = ..., ...)` – stefan Jan 07 '22 at 11:18

0 Answers0