Open Anuragsahucuraj opened 1 year ago
I want to plot 4clusters of each pollutant like BLACK CARBON, OZONE etc separately I plotted a 4 cluster of all air mass trajectories. now from that How can i plot 4 clusters of a pollutant? means what is the contribution of BC in that Particular cluster
Hi Anurag,
You can use a bit of dplyr to calculate any statistic per cluster using the openair trajCluster()
output:
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# get some traj data
traj_data <- openairmaps::traj_data
# cluster
clustered <- openair::trajCluster(traj_data, cols = "Dark2")
# calculate avg (or any stat...) per cluster
avg <-
clustered$data$traj %>%
group_by(cluster) %>%
summarise(
nox = mean(nox, na.rm = TRUE),
o3 = mean(o3, na.rm = TRUE),
pm10 = mean(pm10, na.rm = TRUE),
pm2.5 = mean(pm2.5, na.rm = TRUE)
)
# plot?
library(ggplot2)
ggplot(avg, aes(x = cluster, y = nox)) +
geom_col(aes(fill = cluster), show.legend = FALSE) +
scale_fill_brewer(palette = "Dark2") +
theme_bw() +
labs(y = openair::quickText("Average NOx in cluster (ug/m3)"))
Created on 2023-09-18 with reprex v2.0.2
If you want to put it back on a traj map, you can use the other element of trajCluster()
output, join it to your summary stats, and use trajPlot()
.
clustered$data$results %>%
left_join(avg) %>%
openair::trajPlot(pollutant = "nox")
How can i get to know the contribution of each cluster of each pollutant in %
This is a common plot for all trajectories Like this
I want to plot 4clusters of each pollutant like BLACK CARBON, OZONE etc separately I plotted a 4 cluster of all air mass trajectories. now from that How can i plot 4 clusters of a pollutant? means what is the contribution of BC in that Particular cluster