-6

大家,我对ggplot2不熟悉。现在我对此有疑问。这是生成一个情节的代码

data <- data.frame(age=sample(c("25-29","30-34"),100,rep=TRUE),ratio=rnorm(100,mean=1,sd=0.3))
library(ggplot2)
qplot(ratio, data=data, geom="bar", fill=age, binwidth=0.1)

图1

这是我的问题。
(1) 如何改变直方图的颜色?
(2) 如何在面板中放置图例?
(3) 如何改变背景颜色?

首先十分感谢!

4

1 回答 1

9
  1. Have a look at scale_color_manual, the examples should be sufficient. The general structure of tweaking any scale in ggplot2 is to use the appropriate scale function: scale_{aes_name}_{scale_type}, where aes_name can be color, x, or any other aeshetic, and where scale_type can be continuous, discrete, manual, etc.
  2. Googling for ggplot2 legend position led me to this link. Your answer is in there.
  3. Have a look at ?theme, in particular panel.background. The examples there include an example of exactly what you need.
于 2013-05-05T14:42:54.500 回答