我正在尝试在ggplot中构建一个哑铃形图(geom_dumbbell)。绘图构建得很好,但当我尝试围绕点颜色和大小添加细节时,绘图无法继承aes,因此:
错误:必须由
aes()
创建mapping
以下是生成可重现示例的代码:
test <- data.frame(Scenario = rep(c("LC-HD", "HC-HD", "LC-LD", "HC-LD"), times = 2),
technology = c("P", "W", "P", "W", "P", "W", "P", "W"),
country = paste("country", rep(seq(1, 4, by = 1), times = 2)),
low = runif(8, min = 1, max = 3),
high = runif(8, min = 4, max = 6))
下面的代码运行正常:
library(ggplot2)
library(ggalt)
ggplot(test, aes(x = low, xend = high, y = country, group = country)) +
geom_dumbbell(color="grey",
size = 1) +
facet_grid(technology ~ Scenario) +
coord_flip() +
theme(axis.text.x = element_text(angle = 90))
但是,当我对geom_dumbbell层进行以下更改时(设置点的颜色和大小):
library(devtools)
library(ggplot2)
library(ggalt)
ggplot(test, aes(x = low, xend = high, y = country, group = country)) +
geom_dumbbell(color="grey",
size = 1,
point.size.l = 1.5, point.size.r = 1,5,
point.colour.l = "#58d9ef", point.colour.r = "#a3c4dc") +
facet_grid(technology ~ Scenario) +
coord_flip() +
theme(axis.text.x = element_text(angle = 90))
我得到了错误:
错误:必须由
aes()
创建mapping
即使我尝试在geom_bumbbell层显式地设置inherit.aes = T,我仍然得到错误。
问题似乎出在point.size参数上,因为添加这个参数会产生错误。当我只是添加point.colour参数时,我得到:
警告:忽略未知参数: point.color.l、point.color.r
这很奇怪,因为文档中描述了以下参数:https://www.rdocumentation.org/packages/SciencesPo/versions/1.4.1/topics/geom_dumbbell
我正在运行ggalt_0.6.1 (加载geom_dumbbell)
我在这里错过了什么。为什么在点上添加细节会改变继承aes的方式,为什么point.colour参数无法识别?
发布于 2018-08-28 05:57:20
解决了这个问题。
错误:映射必须由aes()创建
是由point.size.r中的逗号引起的。
警告:忽略未知参数: point.color.l、point.color.r
是由于使用了错误的名字造成的。
它们应该是:
point.size.l = size_x
point.size.r = size_xend
point.color.l = colour_x
point.color.r = colour_xend
解决方案在这里:Ignoring unknown parameters: point.colour.1
对于令人困惑的问题标题,我深表歉意。我不确定如何编辑文档:https://www.rdocumentation.org/packages/SciencesPo/versions/1.4.1/topics/geom_dumbbell
https://stackoverflow.com/questions/52042872
复制相似问题