Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.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_Border_Point - Fatal编程技术网

在r中的特定点中添加边框

在r中的特定点中添加边框,r,ggplot2,border,point,R,Ggplot2,Border,Point,我只想为colunmn'exot'的级别1添加一个边框。我在很多网站上都找过,但我只找到了关于如何进行边界划分的解释(pch等)。图1是一个示例(在photoshop中制作),说明了我希望在图形中使用边框的方式 马上谢谢你的帮助 library(ggthemes) library(ggplot2) p<- ggplot(Dataset, aes(sp,log(num))) p + geom_point(aes(colour=recal, size = pf))+ scale_fil

我只想为colunmn'exot'的级别1添加一个边框。我在很多网站上都找过,但我只找到了关于如何进行边界划分的解释(pch等)。图1是一个示例(在photoshop中制作),说明了我希望在图形中使用边框的方式

马上谢谢你的帮助

library(ggthemes)
library(ggplot2)

p<- ggplot(Dataset, aes(sp,log(num))) 
p + geom_point(aes(colour=recal, size = pf))+
  scale_fill_continuous() +
  scale_size_continuous(range = c(4,10)) +
  ggthemes::theme_few() +
  theme(axis.text.x = element_text(angle = 90, vjust = .5))

sp  num recal   pf  exot
A   47  2   7   0
B 22    0   3   0
C   5   0   0   0
D   4   0   0   0
E   2   0   0   0
F   2   0   0   0
G   2   0   0   1
H   2   0   0   0
I   1   0   1   0
J   1   0   0   0
L 1 5   0   0
M   1   0   0   0
N   1   0   0   0
O   1   0   0   0
P   1   0   0   0
Q   1   0   0   0
R   1   0   0   0
S   1   0   0   1
T   1   0   0   1
U   1   0   0   1
库(ggthemes)
图书馆(GG2)

p一个可以让你更接近的解决方案是对点使用
shape=21
,并将颜色设置为
exot
(注意,现在颜色指的是边框)

使用
scale\u手动
将值设置为
“白色”
“红色”
,然后删除图例:

library(ggthemes)
library(ggplot2)

ggplot(dataset, aes(sp,log(num))) + 
  geom_point(aes(fill=recal, size = pf, color=as.factor(exot)), shape = 21, stroke = 2)+
  scale_fill_continuous() +
  scale_size_continuous(range = c(4,10)) +
  scale_colour_manual(values=c("white", "red")) + # set the border to the bg color
  ggthemes::theme_few() +
  guides(color = FALSE) + # remove the legend for the border
  theme(axis.text.x = element_text(angle = 90, vjust = .5))


如果您仍想为
的“pf”
图例使用“满”点,请使用以下选项:

library(ggthemes)
library(ggplot2)

ggplot(dataset, aes(sp,log(num))) + 
  geom_point(aes(fill=recal, size = pf, color=as.factor(exot)), shape = 21, stroke = 2)+
  scale_fill_continuous() +
  # change guide for the size 
  scale_size_continuous(range = c(4,10), guide=guide_legend(override.aes = list(shape=19))) + 
                                         # ^this part (forces the shape to 19)
  scale_colour_manual(values=c("white", "red")) + # set the border to the bg color
  ggthemes::theme_few() +
  guides(color = FALSE) + # remove the legend for the border
  theme(axis.text.x = element_text(angle = 90, vjust = .5))

数据:


tt Hi@Rlave谢谢你,我用不同的方法尝试了shape=21,但没有用color=as.factor(exot)。非常感谢你的两个例子,即使在其他情节的剧本中,它们也给了我很多帮助。
tt <- "sp  num recal   pf  exot
A   47  2   7   0
B 22    0   3   0
C   5   0   0   0
D   4   0   0   0
E   2   0   0   0
F   2   0   0   0
G   2   0   0   1
H   2   0   0   0
I   1   0   1   0
J   1   0   0   0
L 1 5   0   0
M   1   0   0   0
N   1   0   0   0
O   1   0   0   0
P   1   0   0   0
Q   1   0   0   0
R   1   0   0   0
S   1   0   0   1
T   1   0   0   1
U   1   0   0   1"

dataset <- read.table(text=tt, header=T)