在R添加边框细节点

问题描述 投票:1回答:1

我想添加边框只为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

Figure 1

r ggplot2 border point
1个回答
1
投票

可以让你更接近一种解决方案是使用shape=21的点,设置颜色为exot(现在的颜色是指边境通知)。

使用scale_manual设定值"white"然后"red"删除的传说:

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))

enter image description here


如果你仍然想使用“全”点"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))

enter image description here

数据:

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)
© www.soinside.com 2019 - 2024. All rights reserved.