r - r中的gg图和geom_point函数
问题描述
给定下面的代码,我试图可视化以下分层气泡图:所有起始站的点。大小随皮卡的总数而变化。所有终点站的点。大小随返回的总数而变化。我最终需要一个名为 p1 的 ggplot 对象,两层的 alpha = 0.5。
library(lubridate)
library(tidyverse)
nycbikes18 <- read_csv("data/2018-citibike-tripdata.csv",
locale = locale(tz = "America/New_York"))
nycbikes18
#> # A tibble: 333,687 x 15
#> tripduration starttime stoptime
#> <dbl> <dttm> <dttm>
#> 1 932 2018-01-01 02:06:17 2018-01-01 02:21:50
#> 2 550 2018-01-01 12:06:18 2018-01-01 12:15:28
#> 3 510 2018-01-01 12:06:56 2018-01-01 12:15:27
#> 4 354 2018-01-01 14:53:10 2018-01-01 14:59:05
#> 5 250 2018-01-01 17:34:30 2018-01-01 17:38:40
#> 6 613 2018-01-01 22:05:05 2018-01-01 22:15:19
#> 7 290 2018-01-02 12:13:51 2018-01-02 12:18:42
#> 8 381 2018-01-02 12:50:03 2018-01-02 12:56:24
#> 9 318 2018-01-02 13:55:58 2018-01-02 14:01:16
#> 10 1852 2018-01-02 16:55:29 2018-01-02 17:26:22
#> # … with 333,677 more rows, and 12 more variables:
#> # start_station_id <dbl>, start_station_name <chr>,
#> # start_station_latitude <dbl>, start_station_longitude <dbl>,
#> # end_station_id <dbl>, end_station_name <chr>,
#> # end_station_latitude <dbl>, end_station_longitude <dbl>,
#> # bikeid <dbl>, usertype <chr>, birth_year <dbl>, gender <dbl>
我尝试了下面的代码,但不确定如何修复 n 侧。
p1 <- nycbikes18
p1 <- ggplot(p1) +
geom_point(aes(start_station_longitude,start_station_latitude,
size=n), alpha = 0.5) +
geom_point(aes(end_station_longitude,end_station_latitude, size=n),
alpha = 0.5)
p1
解决方案
在第一次通话中,您正在ggplot()
用“结束站”aes覆盖您的“起始站”美学。geom_point()
根据您的描述,您想要的是:
ggplot(p1) +
geom_point(aes(start_station_longitude,start_station_latitude, size = n_start), alpha = 0.5) +
geom_point(aes(end_station_longitude,end_station_latitude, size = n_end), alpha = 0.5)
尽管如果您分享一个可重现的示例并解释您遇到的错误,您会提高获得帮助的机会。
推荐阅读
- java - 当包含它的服务停止时,协程不会停止
- json - 如何跟踪“请求产品”或“保存”配置
- javascript - 如何编写涵盖 javascript 文件中 const 的代码测试
- vhdl - VHDL试图将信号作为输入
- next.js - 如果我需要在服务器端和客户端访问它,在哪里存储 jwt 令牌?
- pandas - 在 Pandas 中创建条件语句时需要帮助
- java - 编译器如何识别覆盖方法的返回类型在 Java 中不兼容?
- java - 删除后返回 Java 新值
- reactjs - 调用 auth spotify 时出现 graphql 未知错误
- swiftui - Swiftui iOS14.5 键盘隐藏了 DatePicker 但非常适合 TextField