3

在 ggplot2 图中很难使用标签。这是示例页面中的类似图:

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

我将如何定义因子(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 回答