我正在尝试添加条形图的边框。具体地说,下面的图中有没有边线的条形图。如果我添加linetype,两个组都会有边框,但我只需要黑色虚线的‘黑色’组,而保持‘白色’组的颜色,但没有边框。
df1<- data.frame(
score = scores,
count=c(white,black),
race =rep(c("White","Black"),c(length(white),length(black))))
ggplot(df1, aes(score,count,fill=race)) +
geom_bar(aes(fill=race),stat="identity",position="identity") +
scale_fill_manual(values = alpha(c("#ff1212","#1212ff"), 0.25)) +
labs(title="Chart for Phil", y="Percent", x="Score")解决方案的结果如下:

发布于 2020-06-05 05:17:26
不幸的是,由于变量scores、black和white,您的示例不能重现,但我做了一个:
library(ggplot2)
df1<- data.frame(
score = rep(1,1),
count=c(8,5),
race =c("White","Black"))
ggplot(df1, aes(score, count, fill=race, col=race, linetype=race)) +
geom_bar(aes(fill=race),stat="identity",position="identity") +
scale_fill_manual(values = alpha(c("#ff1212","#1212ff"), 0.25)) +
scale_color_manual(values = c("black","black")) +
scale_linetype_manual(values = c("dashed", "blank")) +
labs(title="Chart for Phil", y="Percent", x="Score")发布于 2020-06-05 05:12:01
将linetype = ifelse(race == "Black", "dashed", "blank")添加到geom_bar的aes函数中。
https://stackoverflow.com/questions/62204130
复制相似问题