How to use annotated text style to inherit from theme_set () parameters

How to evenly define text style (size and family) for text elements and additional annotations?

Next MWE

library(ggplot2) 

data1.df <- data.frame(Plant = c("Plant1", "Plant1", "Plant1", "Plant2", "Plant2", 
                                 "Plant2"), Type = c(1, 2, 3, 1, 2, 3), Axis1 = c(0.2, -0.4, 0.8, -0.2, -0.7, 
                                                                                  0.1), Axis2 = c(0.5, 0.3, -0.1, -0.3, -0.1, -0.8))

theme_set(theme_bw() + theme(text=element_text(family="Palatino", size=10)))

ggplot(data1.df, aes(x = Axis1, y = Axis2, shape = Plant, color = Type)) + geom_point(size = 5) +  annotate("text", x=0.4, y=0.0, label="Label", fontface="italic") + theme(legend.position="none")

produces

enter image description here

with "Vivid" that does not meet the definitions of the topic element_text().

+4
source share
1 answer

If ggplot2 loads, this should give you valid properties (if they differ from the defaults):

theme(text = element_text())$text[ c("family", "size") ]

? annotate , ... " , ". , , annotate theme() , . , , : "... . , , , ".

: annotate: " , () =" ", ". , , . , , , :

ggplot(data1.df, aes(x = Axis1, y = Axis2, shape = Plant, color = Type)) + 
       geom_point(size = 5) +  
       annotate("text", x=0.4, y=0.0, label="Label", 
                 family= theme_get()$text[["family"]], 
                 size= theme_get()$text[["size"]]/2.5, 
                 fontface="italic") + 
       theme(legend.position="none")

, "", 2.5 , : rel , theme(axis.title.x = element_text(size = rel(2.5))).

+3

All Articles