I have been playing wrangling the data in the package "gapminder" and produced an interactive plotly plot. But geom_line() does not work. Does someone know why and how to fix this issue? The code below works well-using geom_point() but once it changed to geom_line() it no longer works and gives a blank canvas and no error message. 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")