[英]stacked barplot based color
I don't know how to do this in base graphics. 我不知道如何在基本图形中执行此操作。 But if you are willing to use
ggplot2
, it's pretty easy to do. 但是,如果您愿意使用
ggplot2
,那就很容易做到。 You can for example use the transparency and the color as two distinct things you would like to change. 例如,您可以将透明度和颜色用作您要更改的两个不同的东西。 Here's the code I used.
这是我使用的代码。
require(ggplot2)
# defining the data
set.seed(1)
x<-matrix(runif(40),ncol=10)
df <- data.frame(x=factor(rep(1:ncol(x), each=nrow(x))),
y=as.numeric(x),
part=factor(paste0("part", 1:nrow(x)), levels=paste0("part", nrow(x):1)))
# ggplot call...
ggplot(df, aes(x=x, y=y, fill=x, alpha=part)) +
geom_bar(stat="identity") +
theme_bw(base_size=30) +
scale_x_discrete(name="", breaks=NULL) +
scale_y_continuous(name="") +
scale_fill_discrete(name="", guide="none") +
scale_alpha_discrete(name="", range=c(.3,1))
This gives you the following figure. 这给您下图。
Of course you can then change the colors and transparencies at will. 当然,您可以随意更改颜色和透明胶片。 Just change the
scale_alpha_discrete
and scale_fill_discrete
function calls. 只需更改
scale_alpha_discrete
和scale_fill_discrete
函数调用即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.