Search code examples
rggplot2linegeom

How to format line size in ggplot with multiple lines of different lengths?


I am able to make the plot correctly, but I would like to increase the line sizes to make the plot more readable. When I try size inside the geom_line, my lines get super fat. I have three time series variables (x,y, z) in the dataframe "data", which I want to plot on the y-axis, and they are of different length, meaning the plots start at different time. How can I change the size of the lines without making them huge?

P_comp <- ggplot(data, aes(x=Date))+
  geom_line(aes(y = x, colour = "green"))+
  geom_line(aes(y = y, colour = "darkred"))+
  geom_line(aes(y = z, colour = "steelblue"))+
  theme_ipsum()+
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
  theme(text = element_text(family = "serif"))+
  xlab("Time") + ylab("Value") +
  ggtitle("EPU Indices")+
  theme(plot.title = element_text(hjust = 0.5, family = "serif", face = "plain", size = 16))+
  theme(axis.title.x = element_text(hjust = 0.5, family = "serif", size = 12, face = "plain"))+
  theme(axis.title.y = element_text(hjust = 0.5, family = "serif", size = 12, face = "plain"))
P_comp

This is the plot without using size argument

This is the plot when inputting size= 1 in one of the geom_lines


Solution

  • Your code snippet doesn't show it here, but it sounds like you are setting size = 1 inside the aes() statement. This will add a size aesthetic called "1" and automatically assign a size to it.

    Try this instead: geom_line(aes(y = x, colour = "green"), size = 1)