如何制作显示R中负值的条形图?
我有包括负值的数据,想做一个条形图如何制作显示R中负值的条形图?,r,ggplot2,geom-bar,R,Ggplot2,Geom Bar,我有包括负值的数据,想做一个条形图 genotype<-c("A","B","C") treatment<- c("tr1", "tr2") y<- c(-0.124, -0.083, -0.07, 0.130, 0.216, 0.182) data1<- data.frame (genotype, treatment, y) genotype treatment
genotype<-c("A","B","C")
treatment<- c("tr1", "tr2")
y<- c(-0.124, -0.083, -0.07, 0.130, 0.216, 0.182)
data1<- data.frame (genotype, treatment, y)
genotype treatment y
1 A tr1 -0.124
2 B tr2 0.130
3 C tr1 -0.083
4 A tr2 0.216
5 B tr1 -0.070
6 C tr2 0.182
ggplot(data1, aes(x=genotype, y=y)) +
geom_bar (stat="identity") +
scale_y_continuous(breaks = seq(-1,1,0.2),limits = c(-1,1))
基因型试试这个:
library(ggplot2)
#Code
ggplot(data1, aes(x=genotype, y=y,fill=treatment)) +
geom_bar (stat="identity",position = position_dodge(0.9)) +
scale_y_continuous(breaks = seq(-1,1,0.2),limits = c(-1,1))
输出:
或更多定制:
#Code 2
ggplot(data1, aes(x=genotype, y=y,fill=treatment)) +
geom_bar (stat="identity",position = position_dodge(0.9)) +
scale_y_continuous(breaks = seq(-1,1,0.2),limits = c(-1,1),
labels = scales::percent)+
theme_bw()+
theme(legend.position = 'bottom',
axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.text.y = element_text(color='black',face='bold'),
legend.text = element_text(color='black',face='bold'),
legend.title = element_text(color='black',face='bold'),
axis.title.y = element_text(color='black',face='bold'))+
scale_fill_manual(values=c('red','gray25'))
输出:
@JinwookKim太棒了!我还为您添加了另一个更具定制性的版本!我希望这有帮助!