R 在ggplot2中使图例周围的框变大
我有一个带有图例的情节,图例周围有一个矩形,但矩形与图例内部的东西有一点重叠。有什么办法可以把盒子的尺寸增加一点吗R 在ggplot2中使图例周围的框变大,r,ggplot2,R,Ggplot2,我有一个带有图例的情节,图例周围有一个矩形,但矩形与图例内部的东西有一点重叠。有什么办法可以把盒子的尺寸增加一点吗 这可能会起作用: ggplot(data = data2) + scale_y_reverse(limits = c(1000, 0)) + scale_x_continuous(limits = c(0, 200)) + geom_point(aes(y = Depth, x = C_flux_umol, fill = SampleType, shape = Trap
这可能会起作用:
ggplot(data = data2) + scale_y_reverse(limits = c(1000, 0)) +
scale_x_continuous(limits = c(0, 200)) +
geom_point(aes(y = Depth, x = C_flux_umol, fill = SampleType, shape = TrapType),
colour = "black", stroke = 1, size = 5) +
#geom_point(aes(x = tot_flux2)) +
scale_shape_manual(values = c(25, 22))+
scale_size_manual(values = c(3, 4)) +
ylab("Depth (m)") + xlab("Flux micro-mol/m^2/day") +
guides(fill = guide_legend(override.aes = list(shape = 25))) +
theme_cowplot() +
theme(legend.position = c(.5, .5),
legend.margin = margin(6, 6, 6, 6),
legend.box.background = element_rect(color = "black", size = .5))
如需进一步参考,请检查此尝试在适用于我@tenunbanks的
theme()函数中添加legend.margin=margin(5,5,5,5)
。当我按照您编写的方式运行它时,我根本看不到一个图例框。此外,TrapType现在似乎偏离了SampleType的中心位置。
ggplot(data = data2) + scale_y_reverse(limits = c(1000, 0)) +
scale_x_continuous(limits = c(0, 200)) +
geom_point(aes(y = Depth, x = C_flux_umol, fill = SampleType, shape = TrapType),
colour = "black", stroke = 1, size = 5) +
#geom_point(aes(x = tot_flux2)) +
scale_shape_manual(values = c(25, 22))+
scale_size_manual(values = c(3, 4)) +
ylab("Depth (m)") + xlab("Flux micro-mol/m^2/day") +
guides(fill = guide_legend(override.aes = list(shape = 25))) +
theme_cowplot() +
theme(legend.position = c(0.5, 0.4),
legend.box.background = element_rect(color = "black", size = .5))
ggplot(data = data2) + scale_y_reverse(limits = c(1000, 0)) +
scale_x_continuous(limits = c(0, 200)) +
geom_point(aes(y = Depth, x = C_flux_umol, fill = SampleType, shape = TrapType),
colour = "black", stroke = 1, size = 5) +
#geom_point(aes(x = tot_flux2)) +
scale_shape_manual(values = c(25, 22))+
scale_size_manual(values = c(3, 4)) +
ylab("Depth (m)") + xlab("Flux micro-mol/m^2/day") +
guides(fill = guide_legend(override.aes = list(shape = 25))) +
theme_cowplot() +
theme(legend.position = c(.5, .5),
legend.margin = margin(6, 6, 6, 6),
legend.box.background = element_rect(color = "black", size = .5))