This is the code I am using:
ggplot(data, aes(x = Date1, group=1)) +
geom_line(aes(y = Wet, colour = "Wet")) +
geom_line(aes(y = Dry, colour = "Dry"))
When I use the function size, the lines are too thick and their width is identical from size=0.1 to size=10 or more. Is there a way to control the size of the line?
Dummy data:
Date Wet Dry
July 5.65 4.88
September 5.38 3.93
October 4.73 2.42
One issue that is commonly run into when changing the size using geom_line() is that the size must go OUTSIDE of the aes() commands. If you don't do that, the size argument will always keep the lines at an obnoxious size.
So, instead of:
ggplot(data, aes(x = Date1, group=1)) +
geom_line(aes(y = Wet, colour = "Wet", size = 3)) +
geom_line(aes(y = Dry, colour = "Dry", size = 3))
Try:
ggplot(data, aes(x = Date1, group=1)) +
geom_line(aes(y = Wet, colour = "Wet"), size = 3) +
geom_line(aes(y = Dry, colour = "Dry"), size = 3)
If you find yourself adding multiple geom_line statements, it's because you need to convert your data from wide to long, i.e. one column for variable (Wet/Dry) and another for its values. Then ggplot takes care of everything itself.
library(tidyverse)
data %>%
gather(condition, value, -Date) %>%
mutate(Date = factor(Date,
levels = c("July", "September", "October"))) %>%
ggplot(aes(Date, value)) +
geom_line(aes(color = condition, group = condition), size = 3)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With