r - 将 R 中的 ggplots 与常见图例相结合
问题描述
我有 4 个与此类似的图表(只是使用不同的数据框(don、don1、don2)。我想将它们组合在一个图表中,其中线条颜色指定为具有共同图例的数据框。
ggplot(don, aes(x=poscum, y=pval)) +
# Show all points
geom_line() +
# custom X axis:
scale_x_continuous( label = axisdf$CHR, breaks= axisdf$center ) +
scale_y_continuous(expand = c(0, 0) ) + # remove space between plot area
and x axis
# Custom the theme:
theme_bw() +
theme(
legend.position="none",
panel.border = element_blank(),
panel.grid.major = element_line(colour="white"),
panel.grid.minor = element_line(colour="white"),
axis.ticks = element_line(colour = "black"),
axis.line = element_line(colour = "black"),
)
解决方案
您可以为此使用构面。像这样:
donall <- data.frame(rbind(don, don1, don2), group= rep("don", nrow(don)), rep("don1", nrow(don1)), rep("don2", nrow(don2)))
ggplot(donall, aes(x=poscum, y=pval)) +
geom_line()+
facet_wrap(~group, ncol=2) +....
推荐阅读
- amazon-web-services - 使用 CloudFormation 创建 Secrets Manager,但保持值不可见
- c# - 如何更改 System.Text.Encoding.Default?
- javascript - 反应组件循环
- arrays - 附加 + 删除 Postgres 文本数组元素。导致大量表大小
- machine-learning - 随机森林分类器中的 One-hot 编码
- javascript - 我如何检查用户是否对机器人的消息作出反应,然后如果他没有或如果他有则发送消息(全部在 DM 中)
- react-native - 当我想显示来自 API 的数据时出错
- android - 在文档中添加更多字段而不在 Firebase Cloud Firestore 中覆盖
- sql-server - 将 FireDAC 连接到 SQL Server 数据库
- python - 在 Minio 上上传函数的进度对象是什么?