我想使用scatterpie
. 但是,该函数抛出一个错误,它无法找到与具有 y 坐标值的列对应的对象。
我的资料
library(tidyverse)
library(scatterpie)
my_df <- structure(list(day_in_july = 13:20, yes_and_yes = c(0.611814345991561,
0.574750830564784, 0.593323216995448, 0.610539845758355, 0.650602409638554,
0.57429718875502, 0.575971731448763, 0.545454545454545), yes_but_no = c(0.388185654008439,
0.425249169435216, 0.406676783004552, 0.389460154241645, 0.349397590361446,
0.42570281124498, 0.424028268551237, 0.454545454545455)), row.names = c(NA,
-8L), class = c("tbl_df", "tbl", "data.frame"))
> my_df
## # A tibble: 8 x 3
## day_in_july yes_and_yes yes_but_no
## <int> <dbl> <dbl>
## 1 13 0.612 0.388
## 2 14 0.575 0.425
## 3 15 0.593 0.407
## 4 16 0.611 0.389
## 5 17 0.651 0.349
## 6 18 0.574 0.426
## 7 19 0.576 0.424
## 8 20 0.545 0.455
使用散点图绘制数据失败
我遵循了文档中的代码,但它仍然不适合我。
ggplot() +
geom_scatterpie(aes(x = day_in_july, y = yes_but_no),
data = my_df,
cols = colnames(my_df)[2:3])
## Error in FUN(X[[i]], ...) : object 'yes_but_no' not found
我已经尝试过从之前转换tibble
为a data.frame
,但没有解决问题。
顺便说一句,设置y
为常数(例如,2
)有效:
ggplot() +
geom_scatterpie(aes(x = day_in_july, y = 2),
data = my_df,
cols = colnames(my_df)[2:3]) +
coord_fixed()