Skip to content

Commit 8aa4bea

Browse files
committed
showcase after_stat functionality
1 parent 0f45373 commit 8aa4bea

13 files changed

+49
-0
lines changed

man/figures/make_demo_plots.qmd

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ ggsave(here("man/figures/pointdensity_adj.png"),
121121
width = 18, height = 6, units = "cm", dpi = 300)
122122
```
123123

124+
```{r}
125+
p_neigh <- dat %>%
126+
ggplot(aes(x = x, y = y)) +
127+
geom_pointdensity(method = "neighbors", size = .3) +
128+
scale_color_viridis() +
129+
labs(title="method = \"neighbors\"") +
130+
theme(plot.title = element_text(hjust = 0.5))
131+
132+
p_kde <- dat %>%
133+
ggplot(aes(x = x, y = y)) +
134+
geom_pointdensity(method = "kde2d", size = .3) +
135+
scale_color_viridis() +
136+
labs(title="method = \"kde2d\"") +
137+
theme(plot.title = element_text(hjust = 0.5))
138+
139+
p_neigh + p_kde
140+
ggsave(here("man/figures/pointdensity_methods.png"),
141+
scale = 1.3,
142+
width = 18, height = 6, units = "cm", dpi = 300)
143+
```
144+
145+
124146
Not sure why anyone would do this, but you can use separate bandwidths for x and y:
125147
```{r}
126148
dat %>%
@@ -150,6 +172,20 @@ ggsave(here("man/figures/pointdensity_facet.png"),
150172
width = 14, height = 7, units = "cm", dpi = 300)
151173
```
152174

175+
```{r}
176+
dat %>%
177+
ggplot( aes( x = x, y = y, after_stat(ndensity))) +
178+
geom_pointdensity( size = .25) +
179+
scale_color_viridis() +
180+
facet_wrap( ~ group) +
181+
labs(title="facet_wrap( ~ group)") +
182+
theme(plot.title = element_text(hjust = 0.5))
183+
184+
ggsave(here("man/figures/pointdensity_facet_relative.png"),
185+
scale = 1.3,
186+
width = 14, height = 7, units = "cm", dpi = 300)
187+
```
188+
153189
x- and ylim work as expected:
154190
```{r}
155191
plim <- dat %>%
@@ -210,6 +246,19 @@ ggsave(here("man/figures/pointdensity_custom.png"),
210246
```
211247

212248

249+
```{r}
250+
dat %>%
251+
ggplot(aes(x = x, y = y, color = after_stat(density / max(density)))) +
252+
geom_pointdensity(method = "neighbors", size = .3) +
253+
scale_color_viridis() +
254+
theme(plot.title = element_text(hjust = 0.5)) +
255+
labs(color = "relative\ndensity")
256+
257+
ggsave(here("man/figures/pointdensity_relative.png"),
258+
scale = 1.3,
259+
width = 10, height = 7, units = "cm", dpi = 300)
260+
```
261+
213262

214263
```{r}
215264
date()

man/figures/pointdensity.png

30.6 KB
Loading

man/figures/pointdensity_adj.png

52.8 KB
Loading
69.7 KB
Loading

man/figures/pointdensity_facet.png

30.2 KB
Loading
408 KB
Loading

man/figures/pointdensity_logo.png

42.5 KB
Loading
524 KB
Loading
396 KB
Loading

man/figures/pointdensity_shape.png

26.2 KB
Loading

0 commit comments

Comments
 (0)