GGPLOT2GEOM_BAR颜色根据2vars

问题描述 投票:0回答:1

rm(list=ls()) library(ggplot2) set.seed(123) data=data.frame(hit=sample(1:3,20,replace = TRUE), type=sample(c("A","B","C"),20,replace=TRUE)) ggplot(data,aes(hit,fill=type))+ geom_bar(stat="count",position=position_dodge())

我需要从A到C的梯度,而不同的颜色从1到3my_bar_chart 请评论,如果链接是重复的

我认为以下适合您的作品,从a到c

r ggplot2 colors bar-chart
1个回答
0
投票

library(ggplot2) set.seed(123) data=data.frame(hit = sample(1:3, 20, replace = TRUE), type = sample(c("A", "B", "C"), 20, replace = TRUE)) ggplot(data) + geom_bar(aes(hit, alpha = type, fill = as.factor(hit)), stat = "count", position = position_dodge()) + scale_fill_manual(name = "Hit", values = c("darkblue", "darkgreen", 'darkred')) + scale_alpha_discrete(name = "Type", breaks = c("A", "B", "C"), range = c(0.3, 1))

    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.