Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.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 如何将图例符号与ggplot2上的已包装图例文本对齐_R_Ggplot2_Legend_Figure - Fatal编程技术网

R 如何将图例符号与ggplot2上的已包装图例文本对齐

R 如何将图例符号与ggplot2上的已包装图例文本对齐,r,ggplot2,legend,figure,R,Ggplot2,Legend,Figure,是否有方法将图例符号(红、绿或蓝点)与此示例图上已包装图例文本的第一行对齐?(摘自eipi10) 这是一个细节问题,但一位合著者坚持了这一点。这里有一个解决方案,它是一种通过将背景颜色更改为白色并使用vjust的黑客攻击。我找不到一个简单的方法来顶部对齐框内的点 库(stringr) 图书馆(tidyverse) #创建要包装的长标签 iris$物种=粘贴(iris$物种, “随机文本使标签比原始标签长得多”) ggplot(鸢尾,aes(萼片长度,萼片宽度,颜色=str_-wrap(物种,2

是否有方法将图例符号(红、绿或蓝点)与此示例图上已包装图例文本的第一行对齐?(摘自eipi10)


这是一个细节问题,但一位合著者坚持了这一点。

这里有一个解决方案,它是一种通过将背景颜色更改为白色并使用vjust的黑客攻击。我找不到一个简单的方法来顶部对齐框内的点

库(stringr)
图书馆(tidyverse)
#创建要包装的长标签
iris$物种=粘贴(iris$物种,
“随机文本使标签比原始标签长得多”)
ggplot(鸢尾,aes(萼片长度,萼片宽度,颜色=str_-wrap(物种,20)))+
几何点()+
实验室(color=“长标题缩短,带包装”)+
主题(legend.key.height=单位(2,“cm”),legend.key=元素(fill=“white”))+
辅助线(颜色=辅助线\图例(label.vjust=-1,label.position=“right”))

由(v0.2.1)于2019-01-28创建

library(stringr)
library(tidyverse)

# Create long labels to be wrapped
iris$Species = paste(iris$Species, 
                     "random text to make the labels much much longer than the original labels")

ggplot(iris, aes(Sepal.Length, Sepal.Width, colour=str_wrap(Species,20))) +
  geom_point() +
  labs(colour="Long title shortened\nwith wrapping") +
  theme(legend.key.height=unit(2, "cm"))