如何更改图形标签的颜色标签? (三角形,正方形)的颜色(“红色”,“蓝色”)
ggplot(plasmacicatriz, aes(Carbono, Nitrogeno)) +
geom_errorbar(aes(xmin = -14.7, xmax = -13.9, y = 16.7), width = 0.1) +
geom_errorbar(aes(xmin = -16.1, xmax = -14.6, y = 14.6), width = 0.1) +
geom_errorbar(aes(ymin = 16.5, ymax = 17.0, x = -14.3), width = 0.1) +
geom_errorbar(aes(ymin = 14.2, ymax = 15.1, x = -15.3), width = 0.1) +
geom_point(aes(-14.3, 16.7, color = Cicatriz == "Abierta"), size = 3) +
geom_point(aes(-15.3, 14.6, color = Cicatriz=="Cerrada"), size = 3) +
scale_color_manual(name = "Cicatríz umbilical", values = c("red", "blue"), labels = c("Abierta", "Cerrada")) +
xlim(c(-17, -13)) +
ylim(c(13.5, 17.5)) +
xlab(expression(paste(delta^{13}, "C(‰)"))) +
ylab(expression(paste(delta^{15}, "N(‰)")))
我尝试过
```{r}
ggplot(plasmacicatriz, aes(Carbono, Nitrogeno)) +
geom_errorbar(aes(xmin = -14.7, xmax = -13.9, y = 16.7), width = 0.1) +
geom_errorbar(aes(xmin = -16.1, xmax = -14.6, y = 14.6), width = 0.1) +
geom_errorbar(aes(ymin = 16.5, ymax = 17.0, x = -14.3), width = 0.1) +
geom_errorbar(aes(ymin = 14.2, ymax = 15.1, x = -15.3), width = 0.1) +
geom_point(aes(-14.3, 16.7, shape = Cicatriz == "Abierta"), size = 3) +
geom_point(aes(-15.3, 14.6, shape = Cicatriz=="Cerrada"), size = 3) +
scale_shape_manual(name = "Cicatríz umbilical", labels = c("Abierta", "Cerrada"), values = c(0,1)) +
xlim(c(-17, -13)) +
ylim(c(13.5, 17.5)) +
xlab(expression(paste(delta^{13}, "C(‰)"))) +
ylab(expression(paste(delta^{15}, "N(‰)")))
```
但是结果是这样的,两个元素都有相同的图形,我不知道如何解决它: enter image description here
答案 0 :(得分:0)
也许您可以尝试将“ Cicatriz”作为color
和shape
参数传递到aes
中:
ggplot(plasmacicatriz, aes(Carbono, Nitrogeno, color = Cicatriz, shape = Cicatriz)) +
geom_errorbar(aes(xmin = -14.7, xmax = -13.9, y = 16.7), width = 0.1) +
geom_errorbar(aes(xmin = -16.1, xmax = -14.6, y = 14.6), width = 0.1) +
geom_errorbar(aes(ymin = 16.5, ymax = 17.0, x = -14.3), width = 0.1) +
geom_errorbar(aes(ymin = 14.2, ymax = 15.1, x = -15.3), width = 0.1) +
geom_point(aes(x = c(-14.3,-15.3), y = c(16.7,14.6)), size = 3) +
scale_color_manual(name = "Cicatríz umbilical", values = c("red", "blue"), labels = c("Abierta", "Cerrada")) +
scale_shape_manual(name = "Cicatríz umbilical", values = c(16,17), labels = c("Abierta", "Cerrada"))+
xlim(c(-17, -13)) +
ylim(c(13.5, 17.5)) +
xlab(expression(paste(delta^{13}, "C(‰)"))) +
ylab(expression(paste(delta^{15}, "N(‰)")))
它回答了您的问题吗?
如果没有,请提供此数据集plasmacicatriz
的可复制示例,如以下链接所述:How to make a great R reproducible example