[R] to change the size of the line in the plot created in ggplot2

Giorgio Garziano giorgio.garziano at ericsson.com
Fri Dec 25 10:34:30 CET 2015

Hi Marna,

here is another example that should appear more similar to your scenario
than my previous one.

x <- seq(1:100)

y1 <- x*x
g1 <- rep("y1", 100)
df1 <- as.data.frame(cbind(x, y1), stringsAsFactors=FALSE)
df1 <- as.data.frame(cbind(df1, g1))
colnames(df1)<- c("x", "value", "variable")

y2 <- y1+1500
g2 <- rep("y2", 100)
df2 <- as.data.frame(cbind(x, y2), stringsAsFactors=FALSE)
df2 <- as.data.frame(cbind(df2, g2))
colnames(df2)<- c("x", "value", "variable")

y3 <- y1+6000
g3 <- rep("y3", 100)
df3 <- as.data.frame(cbind(x, y3), stringsAsFactors=FALSE)
df3 <- as.data.frame(cbind(df3, g3))
colnames(df3)<- c("x", "value", "variable")

avg <- (y1+y2+y3)/3
df4 <- as.data.frame(cbind(x, avg))
g4 <- rep("average", 100)
df4 <- as.data.frame(cbind(df4, g4))
colnames(df4) <- c("x", "value", "variable")

df <- data.frame(rbind(df1, df2, df3, df4))

# this is the data to start with ggplot()

# the df rows where the average value is stored
sel <- which(df[,"variable"]=="average")


ggplot(data = df[-sel,], aes(x=x, y=value, group=variable)) + geom_line() +
  geom_line(data = df[sel,], aes(x=x, y=value, group=variable), size=0.5, linetype="dashed", color="blue")

Merry Christmas,


	[[alternative HTML version deleted]]

More information about the R-help mailing list