我在ggplot中使用以下代码制作了一个情节。这是数据源 https://www.dropbox.com/s/xzauims7rqwurga/who_ghg_complete.csv?dl=0
p1 <- ghg_complete %>%
filter(`Country Name` %in% c("United States", "China", "India")) %>%
ggplot(aes(x = year, y = Emissions,
group = `Country Name`, color = `Country Name`)) +
geom_point(size = 2, shape = 21) +
geom_line() +
labs(title = "Greenhouse gas emissions (kt of CO2 equivalent)",
x = NULL,
y = NULL) +
scale_x_discrete(breaks = seq(1970, 2012, by = 5)) +
theme_bw() +
theme(legend.position = "bottom") +
scale_color_brewer(palette = "Set1")
p1
&#13;
ggplotly(p1)
我按照评论中的建议更改了y轴编号,这些评论仍然没有帮助解决问题。 这是代码:
p1 <- ghg_complete %>%
filter(`Country Name` %in% c("United States", "China", "India", "Nepal")) %>%
ggplot(aes(x = year, y = Emissions,
group = `Country Name`, color = `Country Name`)) +
geom_point(size = 2, shape = 21) +
geom_line() +
labs(title = "Greenhouse gas emissions (kt of CO2 equivalent)",
x = NULL,
y = NULL) +
scale_x_discrete(breaks = seq(1970, 2012, by = 5)) +
theme_bw() +
scale_color_brewer(palette = "Set1")
# Convert ggplot object to plotly
gg <- plotly_build(p1) %>%
layout(legend = list(orientation = 'h', y = -0.1))
gg
答案 0 :(得分:1)
ggplotly()
并没有完全将你的ggplot图复制到图中,它在图形上等效。如果你想确保你的阴谋图看起来像你的ggplot图,你需要在图中进一步调整它。例如,要让图例看起来更相似,您可以在%>% layout(legend = list(orientation = 'h', x = 0.35, y = -0.1))
来电添加ggplotly
。您可能需要调整x
和y
值才能完全按照您的喜好排列图例。
正如迈克·怀斯在关于轴标签裁剪的评论中所建议的那样,你可能最好只用兆吨或千兆来代表价值,这样他们就不会有这么多的数量