Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何使注释文本样式继承自主题集()选项_R_Ggplot2 - Fatal编程技术网

R 如何使注释文本样式继承自主题集()选项

R 如何使注释文本样式继承自主题集()选项,r,ggplot2,R,Ggplot2,如何为打印文字元素和其他注释统一定义文字样式(尺寸和族) 以下是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

如何为打印文字元素和其他注释统一定义文字样式(尺寸和族)

以下是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")
库(ggplot2)

data1.df如果加载了ggplot2,则应提供当前有效的属性(如果它们不同于默认值):

注释告诉我们。。。“与典型的geom函数不同,geom的属性不是从数据帧的变量映射而来,而是作为向量映射。”。我假设这意味着
annotate
不会在
theme()
中查找其字体信息,尽管这句话没有具体说明。后来还有一条评论让我认为这可能是设计造成的:“……但所有其他美学都设置好了。这意味着使用此功能创建的图层将永远不会影响图例。”

以及?注释中的注释:“这些不是缩放的,因此您可以(例如)使用color=“red”来获得一个红点。”我认为axis的默认值在大小上有一个特定的比率,但无法在帮助文件中找到细节。这似乎为注释提供了与轴标题相似的大小:

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和使用
主题(axis.title.x=element\u text(size=rel(2.5))

非常感谢!最后一个问题,我的代码出现了一个错误:“在grid.Call.graphics(L_text,as.graphicsAnnot(x$label),x$x,x$y,:Windows字体数据库中找不到字体系列”但我没有更改字体?我如何解决这个问题?这个问题已经有一年多了,你不是发布这个问题的人,所以不清楚这个错误是如何发生的(来自非张贴代码)与我的答案有关。
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")