# What methods are there to make the graphics smoother

• PM is the concentration of PM2.5,
• pop is the number of exposed individuals at the corresponding concentration
• year

Then draw the number of people corresponding to different pm values for different years.

``````library(tidyverse)
library(ggridges)

pm_ua  %>%
mutate(year = factor(year, levels = c("2020", "2010", "2000"))) %>%
ggplot() +
geom_density_ridges(
aes(x = pm, y = year, height = pop, fill = year),
size = 0,
stat = 'identity'
)
``````

But I hope the graphics are smoother. I thought for a long time and used a foolish method, but it seems too unscientific and occupying too much memory.

``````d <- pm_ua %>%
uncount(pop)

d %>%
mutate(year = factor(year, levels = c("2020", "2010", "2000"))) %>%
ggplot() +
geom_density_ridges(
aes(x = pm, y = year, fill = year),
stat = "density_ridges"
)
``````

You could try using slider to calculate a windowed mean of the unsmooth data.

``````library(tidyverse)
library(ggridges)
library(slider)
destfile = "pm_ua_pop.xlsx",
mode = "wb")

pm_ua2 <- pm_ua  |>
mutate(year = factor(year, levels = c("2020", "2010", "2000"))) |>
group_by(year) |>
mutate(mean_pop= slide_mean(pop,before=5L,
after=5L,
complete = FALSE))

ggplot(pm_ua2) +
geom_density_ridges(
aes(x = pm, y = year, height = mean_pop, fill = year),
size = 0,
stat = 'identity'
)
`````` 2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.