繁体   English   中英

R中不正确的绘图

[英]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)

这是图的样子 在此处输入图片说明 如您在此处在Y轴上看到的,这些值已经缩小,我如何像gapminder一样使它合适

我下载了您的文件并将其导入。 为了避免由于空白(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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM