Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.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 在ggplot中向下移动镶嵌面标签_R_Ggplot2_Facet Wrap - Fatal编程技术网

R 在ggplot中向下移动镶嵌面标签

R 在ggplot中向下移动镶嵌面标签,r,ggplot2,facet-wrap,R,Ggplot2,Facet Wrap,如何移动刻面标签(A、B、C),使其位于框内的左上角 样本数据集: date <- as.factor(rep(c(1,2,3,4,5,6,7,8), 7)) chlconc <- runif(56, min = 0.1, max = 15.9) colony <- as.factor(c(rep("A", 24), rep("B", 16), rep("C", 16))) year <- as.factor(c(rep("2014", 8), rep("2016",

如何移动刻面标签(A、B、C),使其位于框内的左上角

样本数据集:

date <- as.factor(rep(c(1,2,3,4,5,6,7,8), 7))
chlconc <- runif(56, min = 0.1, max = 15.9)
colony <- as.factor(c(rep("A", 24), rep("B", 16), rep("C", 16)))
year <- as.factor(c(rep("2014", 8), rep("2016", 8), rep("2017", 8), rep("2016", 8), rep("2017", 8), rep("2014", 8), rep("2017", 8)))
graphvalues <- data.frame(year, date, colony, chlconc)

dateFacet标签位于绘图区域之外,我认为没有办法让它们进入绘图区域。但是,您可以通过添加一个
geom_text()
层,将facetting变量作为标签,并为
geom_text()
层设置x和y值,将其放置在图形的左上角,从而在绘图区域内获得标签。然后还要删除镶嵌面标签

ggplot(graphvalues, aes(date, chlconc, group = year)) + 
  facet_wrap(~colony, ncol = 1) + 
  geom_line(aes(color = year), position = pd) +
  geom_point(aes(color = year), position = pd) +
  scale_y_continuous(limit=c(0, 16), breaks=c(0, 4, 8, 12, 16), labels=c(0, 4, 8, 12, 16)) +
  scale_color_discrete(name="Year") +
  geom_hline(yintercept=2, linetype="dashed") +
  theme_classic() + 
  theme(strip.text = element_blank(), #remove strip text
    strip.background = element_blank()) + #remove strip rectangles
  geom_text(aes(label = colony, x = 0.75, y = 15.5)) #add titles using geom_text()

谢谢!您知道如何将Arial字体系列和大小指定为geom_text()?
ggplot(graphvalues, aes(date, chlconc, group = year)) + 
  facet_wrap(~colony, ncol = 1) + 
  geom_line(aes(color = year), position = pd) +
  geom_point(aes(color = year), position = pd) +
  scale_y_continuous(limit=c(0, 16), breaks=c(0, 4, 8, 12, 16), labels=c(0, 4, 8, 12, 16)) +
  scale_color_discrete(name="Year") +
  geom_hline(yintercept=2, linetype="dashed") +
  theme_classic() + 
  theme(strip.text = element_blank(), #remove strip text
    strip.background = element_blank()) + #remove strip rectangles
  geom_text(aes(label = colony, x = 0.75, y = 15.5)) #add titles using geom_text()