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到3
请评论,如果链接是重复的
我认为以下适合您的作品,从a到c
和:
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))