[英]How to edit scale in ggplot2 legend
我正在使用gapminder
数据集。 我想改变人口传说的比例,而不是科学记数法,每个数字都乘以.00001。 有什么建议么?
gapminder1 <- gapminder %>%
filter(country != "Kuwait")
ggplot(gapminder1) +
geom_point(aes(lifeExp, gdpPercap, size = pop, color = continent)) +
facet_wrap(~ year, nrow = 1) +
scale_y_continuous(trans = "sqrt") +
labs(title = "Plot to recreate",
size = "Population (100k)",
color = "Cotinent") +
xlab("Life Expectancy") +
ylab("GDP per Capita") +
guides(size = guide_legend(order = 1)) +
# theme(legend.title = element_text("Continent")) +
theme_bw()
您可以使用labels = scales::unit_format()
:
ggplot(gapminder1) +
geom_point(aes(lifeExp, gdpPercap, size = pop, color = continent)) +
facet_wrap(~ year, nrow = 1) +
scale_y_continuous(trans = "sqrt") +
scale_size_continuous(labels = scales::unit_format(unit = "", scale = .00001)) +
labs(title = "Plot to recreate",
size = "Population (100k)",
color = "Cotinent") +
xlab("Life Expectancy") +
ylab("GDP per Capita") +
guides(size = guide_legend(order = 1)) +
theme_bw()
如果你不喜欢这个空间,有一个sep =
参数。
您可以使用:
library(ggplot2)
library(gapminder)
options(scipen = 99)
gapminder1 <- gapminder %>%
filter(country != "Kuwait")
ggplot(gapminder1) +
geom_point(aes(lifeExp, gdpPercap, size = pop*.00001, color = continent)) +
facet_wrap(~ year, nrow = 1) +
scale_y_continuous(trans = "sqrt") +
labs(title = "Plot to recreate",
size = "Population (100k)",
color = "Cotinent") +
xlab("Life Expectancy") +
ylab("GDP per Capita") +
guides(size = guide_legend(order = 1)) +
theme_bw()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.