r - ggplot2 - 只为一个几何设置限制
问题描述
可以申请xlim
还是ylim
只申请一个geom_
?
在伪代码中它会是这样的:
library(tidyverse)
cars %>%
ggplot() +
geom_point(aes(...) + xlim(0, 120) + ylim(0, 30)) +
annotate(geom = "point", x = 124, y = 35)
解决方案
您可以通过限制它的 DF 来限制一个 geom,如下所示:
library(tidyverse)
ggplot(cars) +
geom_line(aes(speed, dist)) +
geom_point(
data = cars %>% filter(speed > 10 & speed < 20),
aes(speed, dist)
)
推荐阅读
- python - Pipenv 未设置 PYTHONPATH
- php - PHP AWS Cognito'执行“SignUp”时出错:ResourceNotFoundException:用户池客户端 XXXX 不存在
- javascript - 在只读 html 输入上显示插入符号
- android - 使用共享视图模型掌握详细信息流
- c++ - 如何通过替换顺序代码的 while 循环来添加 OpenMP for 循环
- javascript - To do list in Javascript - 如何始终在列表顶部插入新项目?
- android - 在我将继承从 Activity 更改为 AppCompatActivity 后,ActionBar 菜单改变了它的行为
- vba - 对于每个循环立即跳转到最后一个结果
- java - 如何在项目位置创建的新文件夹中上传文件?
- amazon-web-services - 使用 AWS WAF 阻止 IP,以便只有连接到 VPN 的用户才能访问 CloudFront