我正在编写一个将 plot_ly 用于饼图的函数。参数标签中的波浪号 (~) = ~ 与取消引用运算符 !! 冲突。这个问题有解决方案吗?
pieplotr <- function (df, Property){
Property_Name <- enquo(Property)
Pie <- plot_ly(df,
labels = ~!!Property_Name,
type = "pie")
return(Pie)
}
Toy_dataframe <- data.frame(
Sex = c("Male", "Female", "Female", "Male", "Male","NA"),
Height = c(12,11,7,3,9,NA),
Name = c("John", "Dora", "Dora","Dora", "Anna", "John"),
Last = c("Henry", "Paul", "House", "Houze", "Henry", "Bill"),
Location = c("Chicago", "Chicago", "Portland", "NYC", "NYC", "NYC"),
stringsAsFactors = TRUE)
例如
pieplotr(df = Toy_dataframe,
Property = Name)
我希望返回一个饼图,但我收到以下错误消息:
as.list.environment(x, all.names = TRUE) 中的错误:
找不到对象“名称”