我正在使用 R 的 ggplot 创建静态图,并将其传递到plot.ly 以创建交互式图。我的目标是将分类变量投影到颜色,将数字变量投影到大小。使用 R 的 [iris] 数据可以完美工作 - 就像这样:
testplot <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color=Species, size=Petal.Length)) + geom_point()
py$ggplotly(testplot)
https://plot.ly/~SyTpp/11/sepalwidth-vs-sepallength/
现在,我有了自己的数据集,a, ...
> a
Country OR_Edu OR_Illn total num
Peru 1.75 1.67 25367 10
Philippines 1.33 0.43 33543 1
Rwanda 0.29 4.00 6443 2
Senegal 5.00 1.60 32743 3
Sri Lanka 12.00 6.33 21743 4
Sudan 17.00 0.86 27227 5
Tanzania 0.57 0.71 24312 6
Uganda 13.00 0.60 35466 7
Vietnam 1.62 1.50 34639 8
Zambia 0.86 1.00 16735 9
Zimbabwe 1.25 1.00 33349 10
> summary(a)
Country OR_Edu OR_Illn total num
Peru :1 Min. : 0.290 Min. :0.430 Min. : 6443 Min. : 1.000
Philippines:1 1st Qu.: 1.055 1st Qu.:0.785 1st Qu.:23028 1st Qu.: 3.500
Rwanda :1 Median : 1.620 Median :1.000 Median :27227 Median : 6.000
Senegal :1 Mean : 4.970 Mean :1.791 Mean :26506 Mean : 5.909
Sri Lanka :1 3rd Qu.: 8.500 3rd Qu.:1.635 3rd Qu.:33446 3rd Qu.: 8.500
Sudan :1 Max. :17.000 Max. :6.330 Max. :35466 Max. :10.000
(Other) :5
当我仅使用国家/地区作为分类变量时,它也有效......
testplot <- ggplot(a, aes(OR_Edu, OR_Illn, color=Country)) + geom_point()
py$ggplotly(testplot)
但是当我尝试将“总计”映射到标记的大小时
testplot <- ggplot(a, aes(OR_Edu, OR_Illn, color=Country, size=total)) + geom_point()
py$ggplotly(testplot)
尽管“总计”显然是一个数值,但我收到此错误。
L$marker$size *marker.size.mult 中的错误: 二元运算符的非数字参数
有什么问题吗?有什么想法吗?
还有一件事(也许我需要在一个单独的问题中问这个问题):如何自定义悬停时出现的小弹出框?
非常感谢!
最佳答案
您遇到了一个错误,我们现在已修复它。
请重新安装并重新加载“plotly”包,重新实例化您的 py
对象,它现在应该可以工作:https://plot.ly/~marianne2/38/or-illn-vs-or-edu/
关于r - 使用 R 中的 2 个以上图例到plotly/plot.ly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26102941/