ggplot2 プロットのラベルに苦労しています。例のページからの同様のプロットを次に示します。
mt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point()
mt + facet_grid(. ~ cyl, scales = "free")
factor(cyl) のラベルのリストを定義するにはどうすればよいですか?
私はdata.frame
それ自体でそれを行います:
mtcars$cyl_factor <- factor(mtcars$cyl, labels=c('Four', 'Six', 'Eight'))
ggplot(mtcars, aes(mpg, wt, colour = cyl_factor)) +
geom_point() +
facet_grid(. ~ cyl, scales = "free")
labels
カラー スケールの引数で定義できます。
ggplot(mtcars, aes(mpg, wt, colour=factor(cyl))) +
geom_point() +
scale_colour_discrete(breaks = c("4", "6", "8"),
labels = c("Four", "Six", "Eight"))