4.17 Labels & Annotations: Exercise (3)
- Use the code from Figure 4.6 and try to built the figure that you see below.
- Hint: The graph only shows labels for persons that have high values on both axes (but not necessarily the other one). Use the code below to keep last names for the respective persons (it creates a new variable
last_name2
that then replaces the oldlast_name
):
- Hint: The graph only shows labels for persons that have high values on both axes (but not necessarily the other one). Use the code below to keep last names for the respective persons (it creates a new variable
# data_twitter_influence.csv
data <- read_csv(sprintf("https://docs.google.com/uc?id=%s&export=download",
"1dLSTUJ5KA-BmAdS-CHmmxzqDFm2xVfv6"),
col_types = cols())
data$last_name2 <- NA
data$last_name2[data$followers_count>300000] <- data$last_name[data$followers_count>300000]
data$last_name2[data$n_retweets>20000] <- data$last_name[data$n_retweets>20000]
data$last_name <- data$last_name2
## Parsed with column specification:
## cols(
## screen_name = col_character(),
## n_retweets = col_double(),
## followers_count = col_double(),
## party = col_character(),
## party_color = col_character(),
## first_name = col_character(),
## account_created_at = col_datetime(format = ""),
## account_age_months = col_double(),
## account_age_years = col_double(),
## last_name = col_character(),
## female = col_double()
## )
## Warning: Removed 498 rows containing missing values (geom_text_repel).

Figure 4.7: Labels and annotations