[英]Improper plotly graphs in r
I was trying to implement a gapminder example in R using the plotly package from here which completely worked fine, but when I tried changing the data (here I used my own data set) and it shrank the values on Y-axis of the graph. 我试图使用R从这里开始的plotly包在R中实现gapminder示例,该示例完全正常,但是当我尝试更改数据(在这里使用我自己的数据集)时,它缩小了图的Y轴上的值。 Here is the code
这是代码
library(gapminder)
library(plotly)
library(ggplot2)
gg <- ggplot(gapminder_test, aes(gdpPercap, lifeExp, color = continent)) +
geom_point(aes(size = pop, frame = year, ids = country)) +
scale_x_log10()
ggplotly(gg)
this is how the graph looks like 这是图的样子
As you can see here on Y-axis the values have been shrunk off, how can I make it proper like a similar of gapminder
如您在此处在Y轴上看到的,这些值已经缩小,我如何像gapminder一样使它合适
I downloaded your file and imported it. 我下载了您的文件并将其导入。 To avoid the
lifeExp
column being coerced into a factor because of the blanks (empty cells in your Excel file) you can use na.strings = "N/A"
为了避免由于空白(Excel文件中的空单元格)而将
lifeExp
列强制转换为一个因素,可以使用na.strings = "N/A"
gapminder_test <- read.csv("gapminderData_share.csv", na.strings = "N/A")
If already imported, as MLavoie pointed out, coerce it to numeric with as.numeric
: 如MLavoie所指出的,如果已经导入,则使用
as.numeric
其强制为数字:
gapminder_test$lifeExp <- as.numeric(gapminder_test$lifeExp)
gg <- ggplot(gapminder_test, aes(gdpPercap, lifeExp, color = continent)) +
geom_point(aes(size = pop, frame = year, ids = country)) +
scale_x_log10()
ggplotly(gg)
Chart and animation look fine: 图表和动画看起来不错:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.