You've successfully subscribed to MyPad Blog
Great! Next, complete checkout for full access to MyPad Blog
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Using Google fonts with ggplot2

Using Google fonts with ggplot2

Continuing with the concepts around beautifying visualizations, here is a quick sample around using Google fonts along with ggplot2.

The changes to graphics output with a range of fonts is pretty remarkable and impactful. The below chart drives home the point!

The code for generating the chart above is:

## load rtweet package

# credit:
# install.packages("showtext")

# credit:
## Loading Google fonts (
font_add_google("Gochi Hand", "gochi")
font_add_google("Schoolbell", "bell")

# to get over issues mentioned at

## Automatically use showtext to render text

## search for 18000 tweets using the rstudioconf2020 hashtag
rt <- search_tweets(
  "#rstudioconf2020", n = 18000, include_rts = FALSE

## plot time series of tweets
rt %>%
  ts_plot("3 hours") +
  ggplot2::theme_minimal() +
  ggplot2::theme(plot.title = ggplot2::element_text(face = "bold")) +
    x = NULL, y = NULL,
    title = "Frequency of #rstudioconf2020 Twitter statuses from past 9 days",
    subtitle = "Twitter status (tweet) counts aggregated using three-hour intervals",
    caption = "\nSource: Data collected from Twitter's REST API via rtweet"
  ) + 
  theme(text=element_text(size=16,  family="gochi"))