I want to change the font on the inside of a vistime
object, but it happens to only change the axis font.
library(vistime)
dat <- data.frame(event = 1:4, start = c("2019-01-01", "2019-01-10"))
p <- gg_vistime(dat) +
theme(text = element_text(family = "serif"))
p
I found a solution for ggplot
.
There seems to be no way but to access the aes_params
. Depending on the number of layers/data in the plot, the part that needs to be changed is different (a good way to find the correct one is to change the size of all layers (start with one 1 as in the example and go up to N
) and look at the plot every time p$layers[[1]]$aes_params$size <- 20
).
In the example, the text is in layer 5
. The family aes
is not present but can easily be added.
# Load the vistime library
library(vistime)
# Create a data frame with event numbers and start dates
dat <- data.frame(event = 1:4, start = c("2019-01-01", "2019-01-10"))
# Create a vistime plot using gg_vistime() and assign it to p
p <- gg_vistime(dat) +
theme(text = element_text(family = "serif")) # Change the font family for all other text elements (e.g., axes, title)
# Increase the size and change the font family for event labels
p$layers[[5]]$aes_params$size <- 20
p$layers[[5]]$aes_params$family <- "serif"
# Print the vistime plot object to the console
p
Inspired by this post: Is there a way to change marker size and label font size in an R gg_vistime timeline?