Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: How to plot contributions of different pollutants to different clustered trajectories #364

Open
Anuragsahucuraj opened this issue Sep 2, 2023 · 3 comments
Labels
hysplit 🌐 HYSPLIT trajectories & associated openair functions question Questions about function use or interpretation

Comments

@Anuragsahucuraj
Copy link

Anuragsahucuraj commented Sep 2, 2023

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

@Anuragsahucuraj Anuragsahucuraj added the question Questions about function use or interpretation label Sep 2, 2023
@Anuragsahucuraj

This comment was marked as duplicate.

@jack-davison jack-davison changed the title cluster[Question]: [Question]: How to plot contributions of different pollutants to different clustered trajectories Sep 18, 2023
@jack-davison
Copy link
Collaborator

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")

image

@jack-davison jack-davison added the hysplit 🌐 HYSPLIT trajectories & associated openair functions label Sep 18, 2023
@Anuragsahucuraj
Copy link
Author

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
IGPCARE_LT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hysplit 🌐 HYSPLIT trajectories & associated openair functions question Questions about function use or interpretation
Projects
None yet
Development

No branches or pull requests

2 participants