r - 使用交互式文本绘图不使用 geom_line()
问题描述
我一直在争论包“gapminder”中的数据,并制作了一个交互式的情节图。但是 geom_line() 不起作用。有人知道为什么以及如何解决这个问题吗?下面的代码在使用 geom_point() 时运行良好,但一旦更改为 geom_line(),它就不再工作,并给出一个空白画布并且没有错误消息。 https://rpubs.com/stepminer/829742
library(tidyverse) # includes ggplot2
library(plotly) # interactive charts
# The dataset is provided in the "gapminder" library
library(gapminder)
data1 <- gapminder %>%
filter(country == "Cuba")
data2 <- gapminder %>%
filter(country == "Haiti")
data3 <- gapminder %>%
filter(country == "Jamaica")
data4 <- gapminder %>%
filter(country == "Dominican Republic")
data_all<- bind_rows(data1,data2,data3,data4)
data_ts<- data_all %>% select (-continent, -lifeExp, -pop)
data_ts
p <- data_ts %>%
mutate(gdpPercap=round(gdpPercap,0))%>%
mutate(text = paste("Country: ", country,
"\nGdp per capita: ", gdpPercap, sep="")) %>%
ggplot(aes(x=year,y=gdpPercap, text=text)) +
geom_line(aes(color=country)) +
labs(
title = "GDP Per capita evolution in the Caribbean ",
subtitle = "Source:gapminder",
x = "Year",
y = "GDP Per Capita" )+
theme_minimal() +
theme(legend.position="none")
ggplotly(p, tooltip="text")
解决方案
推荐阅读
- python - 分段错误:在 OSX 上带有 pyqt5 的 QMainWindow 退出按钮上的 11
- android - 如何在 Android 上创建此自定义底部导航
- ldap - 如何将 AD LDS distinctName 属性更新为 Single Value 为 No
- php - 如何通过一些简单的程序将 Sql Query 转换为 Laravel
- kiwi-tcms - 在 kiwi tcms 中的测试运行中如何将测试分配给不同用户的过程
- android - 获取 SSL 握手异常,尝试在 android 应用程序中执行 SSL
- priority-web-sdk - 无法按 CUST 从 CUSTOMERS 表中获取
- oracle-cloud-infrastructure - 无法使用 PUTTY 连接到 Oracle 云计算 VM 实例
- java - HBase 连接在随机时间延迟后被拒绝
- sql - 在 Amazon Redshift 上获取字符串中的最后一个单词