我有一个数据框架,如下所示:
head(all)
basisOfProxy method citation season low high season.method.basis
beetle CRACLE Fletcher et al 2019b Tmin -23.50 -20.40 Tmin_CRACLE_beetle
beetle CRACLE-CA Fletcher et al 2019b Tmin -25.00 -10.40 Tmin_CRACLE-CA_beetle
plant CRACLE Fletcher et al 2017 Tmin -12.18 -11.51 Tmin_CRACLE_plant
plant CRACLE-CA Fletcher et al 2017 Tmin -21.70 -8.10 Tmin_CRACLE-CA_plant
plant cRacle Unpublished Tmin -13.48 -10.53 Tmin_cRacle_plant
plant Unweighted MCR Unpublished Tmin -28.50 -3.16 Tmin_Unweighted MCR_plantstr(all)
'data.frame': 39 obs. of 7 variables:
$ basisOfProxy : chr "beetle" "beetle" "plant" "plant" ...
$ method : chr "CRACLE" "CRACLE-CA" "CRACLE" "CRACLE-CA" ...
$ citation : chr "Fletcher et al 2019b" "Fletcher et al 2019b" "Fletcher et al 2017" "Fletcher et al 2017" ...
$ season : chr "Tmin" "Tmin" "Tmin" "Tmin" ...
$ low : num -23.5 -25 -12.2 -21.7 -13.5 ...
$ high : num -20.4 -10.4 -11.5 -8.1 -10.5 ...
$ season.method.basis: chr [1:39, 1] "Tmin_CRACLE_beetle" "Tmin_CRACLE-CA_beetle" "Tmin_CRACLE_plant" "Tmin_CRACLE-CA_plant" ...我正在尝试使用geom_linerange和ggplot绘制一个图,它是Y轴上范围(从低到高)的框或粗线,其中season.method.basis作为每个数据点的标签,在方向和我正在通信的内容方面类似于this example,但在有一个表示范围的实心条方面,看起来更像this example。
根据我在stackexchange上找到的示例,我尝试了几种不同的方法,例如:
Example 1
ggplot() +
geom_linerange(data = all, aes(x = season.method.basis, ymin = low,
ymax = high, lwd = 1, color = season)) +
scale_y_continuous(c(-30, 30))
#Example 2
ggplot(all) +
geom_linerange(aes(x= season.method.basis, ymin=low, ymax=high, lwd=1, colour=season))
#eExample 3
ggplot(all, aes(x = season.method.basis)) +
geom_linerange(aes(ymin=low,ymax=high), linetype=2,color="blue")我还看到了在ggplot中的例子是一个因素。在其他示例中,是否像文本是我无法判断的因素,因此我尝试将season.method.basis转换为因式,并尝试了这一点。
all$fsmb <- factor(all$season.method.basis)
Example 1
ggplot() +
geom_linerange(data = all, aes(x = fsmb, ymin = low,
ymax = high, lwd = 1, color = season)) +
scale_y_continuous(c(-30, 30))
#Example 2
ggplot(all) +
geom_linerange(aes(x= fsmb, ymin=low, ymax=high, lwd=1, colour=season))
#eExample 3
ggplot(all, aes(x = fsmb)) +
geom_linerange(aes(ymin=low,ymax=high), linetype=2,color="blue")每个变体都会导致相同的错误。
看起来类似的例子包括this,但它们指定了y= xmin=和xmax=,它们当时被x、ymin和ymax所忽略,而我已经(尝试过了?)指定x,ymin和ymax。
This one也是相同的错误,但是我将它们连在一起,因此解决方案似乎不适用于这里。
Here --他们根本没有指定x,而我相信至少在一些例子中,我的位置与答案中推荐的位置相同。
我想我错过了一些简单的东西,但我很困惑。
发布于 2022-02-20 15:22:02
此错误似乎是由于与其他库的冲突造成的。我不知道哪个图书馆。为了解决这个错误,我卸载了所有库,重新启动了R,并且只加载了ggplot2。在运行我在上面的注释中指出的代码时,它现在产生的结果与问题的OP相同。我试着重新运行上面的代码,现在我得到了(可怕的!)阴谋而没有错误。
https://stackoverflow.com/questions/71195430
复制相似问题