1

I am a R-noob and need help with designing a plot. I have the plot mostly done however I cannot change the design of one of the two regression lines. I would like to have one of the lines to be dotted so that the plot is understandable when printed in B&W. Also, I would like to describe the plot in the caption in accordance with APA style. However, the caption is too long. How can I get the caption to use several lines instead of one way too long line? This is what I have so far:

P1plotV1.1 <- ggplot(subPD, 
                     aes(x = subPD$Digit, y = subPD$Phoflu_tot, shape = Group, color=Group)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(title="Primary analysis") + 
  labs(x="Digit span") + 
  labs(y="Phonemic fluency") +
  labs(caption="test")

Which gives me the plot attached. I would be happy about any suggestion on how I can change one of the regression lines to a dotted line.

enter image description here

Axeman
  • 32,068
  • 8
  • 81
  • 94
  • 2
    Don't use `$` inside `aes`. Can't you just add `lty = Group` inside `aes`? You can line breaks in the caption with `\n`. – Axeman Feb 24 '17 at 13:59
  • Provide your data so that your plot is reproducible (see [how to make a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5965451#5965451)) or use a default dataset such as iris or cars. – Paul Rougieux Feb 24 '17 at 15:25

1 Answers1

0

Use the linetype aesthetic with a manual scale scale_linetype_manual to specify which groups should have a dotted or continuous line. For example using the iris dataset.

library(ggplot2)
ggplot(iris, 
       aes(x = Sepal.Length, y = Petal.Length, 
           shape = Species, color=Species, 
           linetype = Species)) + # linetype defines the dotted lines
    geom_point() +
    # Choose the linetype, in the order of the Species factor 
    # value 1 produces a continuous line, 
    # other values give various large or finely dotted lines
    scale_linetype_manual(values = c(1,2,3)) + 
    geom_smooth(method = "lm", se = FALSE) +
    labs(title="Primary analysis with a very long title \n and a new line if you prefer",
         subtitle = "Subtitle") 

enter image description here

Paul Rougieux
  • 10,289
  • 4
  • 68
  • 110