R 注释字体不同于带有ggplot2的图中的其他文本
我正在尝试向使用ggplot2创建的图形添加一些注释。与其他内容相比,注释的字体大小和类型似乎有所不同。我的标签和图例的字体大小为20,但即使大小为12并将字体类型(系列)指定为Arial,注释看起来也与图中的其他部分大不相同R 注释字体不同于带有ggplot2的图中的其他文本,r,ggplot2,R,Ggplot2,我正在尝试向使用ggplot2创建的图形添加一些注释。与其他内容相比,注释的字体大小和类型似乎有所不同。我的标签和图例的字体大小为20,但即使大小为12并将字体类型(系列)指定为Arial,注释看起来也与图中的其他部分大不相同 fontsize <- 20 / .pt plot <- ggplot(material) + theme_void() + scale_color_hue() + aes(x = strain, y = stress, colour = type, gro
fontsize <- 20 / .pt
plot <- ggplot(material) + theme_void() + scale_color_hue() +
aes(x = strain, y = stress, colour = type, group = type) +
geom_xspline(size = 1, spline_shape = 0.5) + labs(x = "Strain (in/in)",
y = "Stress (ksi)", color = element_blank()) + theme(legend.position = "bottom",
legend.box.background = element_rect(colour = "black", size = 0.5),
axis.title.y = element_text(size=20, colour="black", angle = 90, vjust = -22, hjust = 0.55),
axis.title.x = element_text(size=20, colour="black", vjust = 7, hjust = 0.6),
axis.text.y = element_blank(), axis.text.x = element_blank(),
legend.text=element_text(size=20), legend.box.margin = margin(10,10,10,10),
legend.spacing.x = unit(0, 'cm')) +
scale_y_continuous(trans = "reverse") + scale_x_continuous(trans = "reverse") +
geom_vline(aes(xintercept = 0), size = 0.3) + geom_hline(aes(yintercept = 0), size = 0.3) +
geom_segment(aes(x = 0, y = 0, xend = -0.0009226, yend = 0), size = 1) +
geom_segment(aes(x = -0.0009226, y = 0, xend = -0.0011707, yend = -0.94), size = 1) +
geom_segment(aes(x = 0, y = -4.958, xend = -0.00333, yend = -4.958),
size = 0.6, linetype = "dotted", colour = "black") +
geom_segment(aes(x = -0.00333, y = 0, xend = -0.00333, yend = -4.958),
size = 0.6, linetype = "dotted", colour = "black") +
geom_segment(aes(x = -0.0024, y = 0, xend = -0.0024, yend = -4.958),
size = 0.6, linetype = "dotted", colour = "black") +
geom_segment(aes(x = -3.75E-03, y = 0, xend = -3.75E-03, yend = -4.6011),
size = 0.6, linetype = "dotted", colour = "black") +
geom_segment(aes(x = -0.0046736, y = 0, xend = -0.0046736, yend = -4.6011),
size = 0.6, linetype = "dotted", colour = "black") +
annotate("text", x = 0, y= -0.94, label = "f'", size = fontsize, family = "sans")
fontsize问题是主题
中的字体大小
通常在pt
(点)中指定,而在geom
s或注释内指定大小时,它的测量单位为mm
。这意味着轴标题的大小为20pt
,而注释的大小为12mm
或约为34pt
。因此,如果您想要相同的字体大小,则必须进行转换,ggplot2
为其提供了一个辅助常量.pt
如果希望注释的大小与轴标题相同,则必须将注释中的字体大小设置为20/.pt
库(ggplot2)
family I刚刚按照您的建议更新了fontsize,但实际上字体看起来比主题()文本小得多。我已经更新了原始帖子,以显示更新后的figureHi Maral。我知道你的意思。当我看这个图时,似乎轴和图例文本比注释要大。尽管如此,我想事实并非如此。作为检查和干净的比较,使用例如应变(in/in)
代替f'
作为绘图注释。