在r中的特定点中添加边框
我只想为colunmn'exot'的级别1添加一个边框。我在很多网站上都找过,但我只找到了关于如何进行边界划分的解释(pch等)。图1是一个示例(在photoshop中制作),说明了我希望在图形中使用边框的方式 马上谢谢你的帮助在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
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)