3

ggplot2 プロットのラベルに苦労しています。例のページからの同様のプロットを次に示します。

mt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point() 
mt + facet_grid(. ~ cyl, scales = "free")

factor(cyl) のラベルのリストを定義するにはどうすればよいですか?

4

2 に答える 2

4

私は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")
于 2012-06-12T22:09:09.880 に答える
2

labelsカラー スケールの引数で定義できます。

ggplot(mtcars, aes(mpg, wt, colour=factor(cyl))) + 
  geom_point() +
  scale_colour_discrete(breaks = c("4", "6", "8"),
                        labels = c("Four", "Six", "Eight"))
于 2012-06-12T22:59:50.260 に答える