r - geom_smooth() 创建多条线,可能是美学问题
问题描述
(尝试寻找其他问题,找不到好的问题。)
我正在尝试创建一条 geom_smooth() 线,但我不断收到多个。这是我的代码:
plot1 <-
ggplot(gapminder) +
aes(y = lifeExp, x = gdpPercap, shape = continent, color = year) +
labs(y = "Life Expectancy") + guides(color = "none") +
geom_point() +
scale_x_log10()
plot1 + geom_smooth()
我相信这与我将美学放在哪里或我如何自行格式化它们有关。
任何帮助表示赞赏。
哦,澄清一下,每个大陆都有不同的线路。我只想要一条整体线。
谢谢你。
解决方案
我想到了。我只需要将形状和颜色的美学直接移入geom_point()
,但不理会轴。
这是正确的代码:
plot1 <-
ggplot(gapminder, mapping = aes(y = lifeExp, x = gdpPercap)) +
labs(y = "Life Expectancy") +
geom_point(mapping = aes(shape = continent, color = year)) +
guides(color = "none") +
scale_x_log10()
plot1 +
geom_smooth()
谢谢你。
推荐阅读
- c# - 为什么在非异步方法中包装参数验证是可取的?
- pine-script - 仅当语句为真时如何使用 plotcandle() 函数?
- reactjs - pwa-spring boot-react-thymeleaf
- javascript - Bootstrap 无法修改标头信息
- typescript - 我有两个接口,我只想合并接口的 id
- traffic - 有没有办法批量导出带有附加文件的 TLS 状态?
- python - 读取 txt 文件会导致数组不可读
- php - 在 print_r 中解析 PHP 中的数组
- python - 使用 Python 重命名给定目录中的所有 xml 文件
- python - 创建一个从 2 到 20 的偶数数组。然后使用 for 循环和附加函数,将可被 7 整除的数字从 30 到 50 插入到 pytho 中的该数组中