【发布时间】:2016-01-31 03:42:42
【问题描述】:
我正在尝试绘制分组条形图。我想为 >=1 的条着色,并将其余的条保留为未填充。我该怎么做?
这是我的代码
data = read.csv ("/home/paul/Desktop/dataset.csv")
library(reshape2)
library(ggplot2)
df.long<-melt(data)
df.long$names <- factor(df.long$names, levels=unique(df.long$names))
ggplot(df.long,aes(x=names,y=value,fill=variable))+ labs(x = "x", y = "y" ) + ylim(0, 2) +
geom_bar(stat="identity",position="dodge") +
scale_fill_hue(l=40) +
theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))
我的数据
names d1 d2
E1 1.30 1.27
K2 1.05 1.86
D4 0.94 1.51
E2 1.01 1.62
N1 1.17 1.47
Q3 1.22 1.51
S7 1.00 1.24
G2 0.78 0.96
H5 1.04 1.04
T1 1.04 1.14
A5 0.71 0.71
P4 1.03 1.27
Y2 1.34 0.58
V4 0.83 0.50
M3 1.02 0.53
C7 0.98 0.31
【问题讨论】:
-
添加一个变量
isColored到您的数据框中,如果您想为项目着色,该变量 == 1,并在您的aes中使用color = isColored或fill = isColored。