[英]How to edit scale in ggplot2 legend
I am working with the gapminder
data set.我正在使用
gapminder
数据集。 I would like to change the scale on the population legend so instead of scientific notation, each number is multiplied by.00001.我想改变人口传说的比例,而不是科学记数法,每个数字都乘以.00001。 Any suggestions?
有什么建议么?
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()
You can use labels = scales::unit_format()
:您可以使用
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()
There is a sep =
argument if you don't like the space.如果你不喜欢这个空间,有一个
sep =
参数。
You can use:您可以使用:
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.