在 r 中的特定点添加边框
Adding border in specifics points in r
我只想为列的第 1 级添加边框 'exot'。我在很多网站上都找过,但我只找到了一般情况下如何设置边界的解释(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
一个可以让你更接近的解决方案是对点使用 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))
如果您仍想为 "pf"
的图例使用 "full" 点数,请使用:
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 <- "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)
我只想为列的第 1 级添加边框 'exot'。我在很多网站上都找过,但我只找到了一般情况下如何设置边界的解释(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
一个可以让你更接近的解决方案是对点使用 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))
如果您仍想为 "pf"
的图例使用 "full" 点数,请使用:
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 <- "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)