r - R - 仅在 ggplot2 的图例中更改形状
问题描述
我的情节目前看起来像这样:
我想只为指示各自颜色的点更改图例中的形状(当前为“a”)。到目前为止,这是我的代码:
ggplot(data=pca2.data, aes(x=X, y=Y, label=Sample, colour = col)) +
geom_text() +
xlab(paste("PC1 - ", pca2.var.per[1], "%", sep="")) +
ylab(paste("PC2 - ", pca2.var.per[2], "%", sep="")) +
theme_bw() +
ggtitle("My PCA Graph") +
geom_hline(yintercept = 0) +
geom_vline(xintercept = 0) +
scale_color_manual(values=c("black", "red", "green"), labels = c("No significant difference", "Sharpe Decrease", "Sharpe Increase")) +
theme(legend.position = 'bottom') + guides(color=guide_legend(""))
我已经尝试在“guide_legend”中添加“shape = c(20, 20, 20)”,但没有任何改变。
解决方案
只需放置一个空点图层,不要绘制图例geom_text
由于您没有提供数据,因此我使用mtcars
了数据集,但它应该可以转化为您的问题
ggplot(mtcars, aes(mpg, cyl, label=rownames(mtcars), color=factor(carb))) +geom_point(shape=NA)+
geom_text( show.legend = F ) + guides(colour=guide_legend(override.aes = list(shape = 16)))
推荐阅读
- javascript - TypeError:无法读取未定义反应的属性“图像”
- crystal-reports - 如何在现有水晶报表的末尾添加完整的新页面?
- .net - ASPNET Identity 2.0 - UserManager.Update 不适用于某些用户
- c++ - 如何使用移位在 C++ 中的 char 数组中插入整数?
- mongodb - 根据另一个集合字段值设置一个 MongoDB 集合字段值
- html - 当我单击锚标记的 ext 时,它不会将我带到另一个页面
- python - 在 Pandas DataFrame 中创建列的用户输入
- javascript - 在逗号分隔字符串的每个第一个位置插入一个文本元素
- javascript - 无法使用 expo-cli 安装反应原生依赖项
- php - 在登录过程中添加操作