[英]Improper plotly graphs in r
我试图使用R从这里开始的plotly包在R中实现gapminder示例,该示例完全正常,但是当我尝试更改数据(在这里使用我自己的数据集)时,它缩小了图的Y轴上的值。 这是代码
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)
我下载了您的文件并将其导入。 为了避免由于空白(Excel文件中的空单元格)而将lifeExp
列强制转换为一个因素,可以使用na.strings = "N/A"
gapminder_test <- read.csv("gapminderData_share.csv", na.strings = "N/A")
如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)
图表和动画看起来不错:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.