Wednesday, 12 October 2011

R - GGplot with white background

I wanted to draw a graph without lines and backgrounds. The relevant code is:

opts(panel.grid.minor = theme_blank(), panel.grid.major = theme_blank(), panel.background = theme_blank())


Example:

s = seq(-2*pi, 2*pi, length.out = 1000)

dat = data.frame(x = s)

ggplot(dat) +
geom_line(aes(x = x, y = sin(1*x)), size = 2, color = "red") +
geom_line(aes(x = x, y = sin(1.1*x)), size = 2, color = "red", linetype="dashed") +
opts(
panel.grid.minor = theme_blank(),
panel.grid.major = theme_blank(),
panel.background = theme_blank()
)

1 comment: