在多彩多姿的分组条形图中更改轮廓的颜色
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在多彩多姿的分组条形图中更改轮廓的颜色相关的知识,希望对你有一定的参考价值。
这是我的条形图:
如何为每个条形图显示黑色轮廓,还可以更改标签上的轴标签和值的字体大小?
mm1=melt(data[,c('label','cut_scorer1','cut_scorer2')], id = 1)
assign(cut_score,ggplot(mm1, aes(x = label, y = value, width = 0.8)) +
geom_bar(aes(fill = variable), stat = "identity", position = "dodge")+ sale_fill_manual(values=alpha(c('light green','dark green'),0.7), name = "Scorer",
labels = c("1", "2")) +
labs(title = paste(subject_name,"Cutting", sep = " - "), x = "", y =
"Score") +
theme(text = element_text(size = 15)) + coord_cartesian( ylim =
c(min(mm1$value),max(mm1$value))))
我真的建议您查看geom_bar()
的文档(以及基本的ggplot2
文档),但这可能有助于您入门。
您可以使用colour = "black"
为条形添加轮廓,并且可以使用labs()
更改轴标签。我们使用theme()
中的参数来更改轴标签和刻度线上的字体大小。请参阅以下代码:
# example dataframe
df <- data.frame(time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")),
total_bill = c(14.89, 17.23))
plot <- ggplot(data = df, aes(x = time, y = total_bill, fill = time)) +
geom_bar(colour = "black", stat = "identity") +
labs(x = "Meal", y = "Total Bill") +
theme(axis.title.x = element_text(size = 13, face = "bold"),
axis.title.y = element_text(size = 13, face = "bold"),
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12))
print(plot)
我找到了解决方案,谢谢。
我在geom_bar中添加了color =“black”但在aes之外
mm1 = melt(data [,c('label','cut_scorer1','cut_scorer2')],id = 1)assign(cut_score,ggplot(mm1,aes(x = label,y = value,width = 0.8)) + geom_bar(aes(fill = variable),stat =“identity”,color =“black”,position =“dodge”)+ scale_color_manual(values ='black')+ scale_fill_manual(values = alpha(c('light green') ,'深绿色'),0.7),name =“Scorer”,labels = c(“1”,“2”))+ labs(title = paste(subject_name,“Cutting”,sep =“ - ”),x =“”,y =“得分”)+主题(text = element_text(size = 15))+ coord_cartesian(ylim = c(min(mm1 $ value),max(mm1 $ value))))
以上是关于在多彩多姿的分组条形图中更改轮廓的颜色的主要内容,如果未能解决你的问题,请参考以下文章