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. 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
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"
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
:
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.