-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprac8.R
30 lines (25 loc) · 815 Bytes
/
prac8.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library(tidyverse)
library(dslabs)
data(murders)
library(ggthemes)
library(ggrepel)
ds_theme_set()
r <- murders %>%
summarise(rate = sum(total)/ sum(population) * 10^6) %>%
pull(rate)
p <- murders %>% ggplot(aes(population/10^6,total,label=abb)) +
geom_abline(intercept = log10(r),lty=2,color='darkgrey') +
geom_point(aes(col=region),size=3)+
geom_text_repel() +
scale_x_log10() +
scale_y_log10() +
xlab("Population in millions (log scale)") +
ylab("Total number of murders (log scale)") +
ggtitle("US Gun Murders in 2010") +
scale_color_discrete(name = "Region") +
theme_economist()
#local pref can override global aes pref
# p <- murders %>% ggplot(aes(population/10^6,total,label=abb)) +
# geom_point(size=3) +
# geom_text(aes(10,800,label='Hello there'))
print(p)