r - 从 ggplot geom_crossbar 中删除等高线
问题描述
下面是一个数据集示例和带有 geom_crossbar 的绘图代码,它让我接近我正在寻找的东西,除了我找不到删除条形周围黑色轮廓线的方法。
data = data.frame(age = c(10,12,14,16,18),
height_min = c(120,140,148,150,150),
height_max = c(150,165,172,175,175))
ggplot(data) +
geom_crossbar(aes(ymin= height_min, ymax=height_max, x=age, y=height_min),
fill = "gray70", fatten=0) +
theme_bw() +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
theme(panel.border = element_blank()) +
theme(axis.line = element_line(colour = "black")) +
labs(x=expression(paste("Age (years)")),
y=expression(paste("Height (cm)"))) +
theme(plot.margin = unit(c(1,1,1,1), "cm")) +
theme(axis.text=element_text(size=20),
axis.title=element_text(size=30,face="bold"))
如何删除条形周围的黑色轮廓线?
解决方案
您可以在 geom_crossbar 中添加“linetype = 0”或“color = NA”。如果您不需要导出绘图,“size=0”也可以工作(否则条形消失)。
以下是可能对其他人有用的代码:
data = data.frame(age = c(10,12,14,16,18),
height_min = c(120,140,148,150,150),
height_max = c(150,165,172,175,175))
ggplot(data) +
geom_crossbar(aes(ymin= height_min, ymax=height_max, x=age, y=height_min),
fill = "gray70", fatten=0, linetype = 0) +
theme_bw() +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
theme(panel.border = element_blank()) +
theme(axis.line = element_line(colour = "black")) +
labs(x=expression(paste("Age (years)")),
y=expression(paste("Height (cm)"))) +
theme(plot.margin = unit(c(1,1,1,1), "cm")) +
theme(axis.text=element_text(size=20),
axis.title=element_text(size=30,face="bold"))
感谢 dc37 的评论!
推荐阅读
- java - 如何在 Java 中使用 Selenium 提交表单
- javascript - 如果用户在出站呼叫中未接听,Twilio 会发送语音消息
- android - 在 NestedScrollView 中使用 RecyclerView 进行分页
- python - 错误=193,%1 不是一个有效的 Win32 应用程序,它带有到 Python 脚本的管道
- dart - 尝试使用导航器页面访问时找不到 Flutter scoped_model
- javascript - 如何将父元素名称添加到子元素
- python - TensorFlow logits 到 one_hot 编码
- java - 语言更改后自定义选项卡布局为空
- c# - Microsoft Graph .NET 客户端库:将成员和团队添加到组
- clojure - 在clojure中使用instaparse后如何按键检索元素?