Reputation: 5154
I am trying to plot a line graph by group in R
using ggplot2
as follows. It is intended for a grayscale print.
library(ggplot2)
# Summarise data
mry <- do.call(rbind, by(movies, round(movies$rating), function(df) {
nums <- tapply(df$length, df$year, length)
data.frame(rating=round(df$rating[1]), year = as.numeric(names(nums)), number=as.vector(nums))
}))
p <- ggplot(mry, aes(x=year, y=number, colour=factor(rating)))
p + geom_line() + scale_color_grey() + theme_bw()
However the clarity is lacking in the resulting plot as there are 10 groups involved. How to adjust the colors/pch/line style in ggplot2 for better readability in such a case where large number of groups are involved?
Upvotes: 0
Views: 1211
Reputation: 59415
I'd be inclined to use facets, like this:
ggplot(mry, aes(x=year, y=number))+
geom_line() +
scale_color_grey() +
theme_bw() +
facet_grid(rating~.)
Obviously this would be better in portrait mode, but even at this minuscule scale you can tell that ratings of 1,2,3,9, and 10 are extremely rare, and that the most common ratings are 6 and 7 (at least recently). This is much more than you can get from plotting everything on top of each other.
Upvotes: 2
Reputation: 13580
An option to improve readability is to use linetype
instead of colour
. But still, 10 groups are probably too many. You could try to add different point shapes with geom_point
p <- ggplot(mry, aes(x=year, y=number, linetype =factor(rating)))
p + geom_line() + scale_color_grey() + theme_bw()
Upvotes: 1