ggplot2包中的颜色使用
载入数据
# Two variables
df <- read.table(header=TRUE, text='
cond yval
A 2
B 2.5
C 1.6
')
# Three variables
df2 <- read.table(header=TRUE, text='
cond1 cond2 yval
A I 2
A J 2.5
A K 1.6
B I 2.2
B J 2.4
B K 1.2
C I 1.7
C J 2.3
C K 1.9
')
基本绘图
library(ggplot2)
library(gridExtra)
# 默认的灰色条形图
p1 <- ggplot(df, aes(x=cond, y=yval)) + geom_bar(stat="identity")
# 设置轮廓颜色
p2 <- ggplot(df, aes(x=cond, y=yval)) + geom_bar(stat="identity", colour="#FF9999")
# 设置轮廓和内部颜色
p3 <-