4.20 Axes
- We can modify axes/scales using various functions as depicted in Figure 4.9.
xlab()
andylab()
: Set labelsscale_color_manual()
: Manually set the color scale (same logic for other scales)scale_x_continuous()
: Manually set a numeric scalexlim()
andylim()
: Set limits
# data_twitter_influence.csv
data <- read_csv(sprintf("https://docs.google.com/uc?id=%s&export=download",
"1dLSTUJ5KA-BmAdS-CHmmxzqDFm2xVfv6"),
col_types = cols())
ggplot(data %>% filter(followers_count<50000),
aes(x = account_age_years,
y = followers_count,
color = factor(female))) +
geom_point(alpha =0.5) +
facet_wrap(~party) +
ylab("Number of followers") +
xlab("Account age (in years)") +
scale_colour_manual(name = "Gender",
values = c("0" = "pink", "1" = "blue"),
labels = c("0" = "male", "1" = "female")) +
scale_x_continuous(breaks = c(0, 5, 10), limits = c(0,10)) +
xlim(0,5) # Replaces x-scale characteristics before
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
## Warning: Removed 302 rows containing missing values (geom_point).

Figure 4.9: Modifying scales and axes