Search code examples
rfontsgplots

How to change the Font in your legend to a windows font


How can I change the Font and the size in R. I want it Times New Roman is it possible. Where should I put the command this the script that I've been trying to change the font


Solution

  • If you're referring to changing the font in a plot's legend and labels. Then here is a possible solution using ggplot2. A full list of fonts can be found here.

    library(tidyverse)
    
    df <- data_frame(a=runif(100), 
                     b=runif(100),
                     c=sample(c("Class A","Class B"), 100, T))
    
    ggplot(df, aes(x=a,y=b,colour=c)) +
      geom_line() +
      theme(text=element_text(family="Times"))