Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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,我想在绘图区域的顶部添加一些文本(真实数据的p值)。下面是一个示例和我尝试的内容: 数据: 接下来,我试着: gt <- ggplot_gtable(ggplot_build(p)) gt$layout$clip[gt$layout$name == "panel"] <- "off" grid::grid.draw(gt) gt使用cowplot我会做什么: p使用cowplot我会做什么: p您也可以尝试facet\u grid方法 library(tidyverse) g

我想在绘图区域的顶部添加一些文本(真实数据的p值)。下面是一个示例和我尝试的内容:

数据:

接下来,我试着:

gt <- ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name == "panel"] <- "off"
grid::grid.draw(gt)

gt使用
cowplot
我会做什么:


p使用
cowplot
我会做什么:


p您也可以尝试
facet\u grid
方法

library(tidyverse)
ggplot(plt, aes(x= Species, y = Petal.Width)) +
  geom_violin() +
  facet_grid(~Species, scales = "free_x", labeller = 
               labeller(Species =set_names(as.character(plt.text$label), plt.text$Species))) +
  theme_minimal(base_size = 14) + 
  theme(panel.background = element_rect(fill = "lightgrey", color="lightgrey"),
        panel.spacing.x =unit(0, "cm"))

您也可以尝试
facet\u grid
方法

library(tidyverse)
ggplot(plt, aes(x= Species, y = Petal.Width)) +
  geom_violin() +
  facet_grid(~Species, scales = "free_x", labeller = 
               labeller(Species =set_names(as.character(plt.text$label), plt.text$Species))) +
  theme_minimal(base_size = 14) + 
  theme(panel.background = element_rect(fill = "lightgrey", color="lightgrey"),
        panel.spacing.x =unit(0, "cm"))

您可以用于打印批注。您可以用于打印批注。回答得很好。我从没想过要把两块地叠在一起!回答得很好。我从没想过要把两块地叠在一起!
library(tidyverse)
ggplot(plt, aes(x= Species, y = Petal.Width)) +
  geom_violin() +
  facet_grid(~Species, scales = "free_x", labeller = 
               labeller(Species =set_names(as.character(plt.text$label), plt.text$Species))) +
  theme_minimal(base_size = 14) + 
  theme(panel.background = element_rect(fill = "lightgrey", color="lightgrey"),
        panel.spacing.x =unit(0, "cm"))