在ggplot(点图)中,是否可能减少离散比例尺下轴与数据之间的空间。我看到了很多关于离散比例尺的方法,但似乎在这种情况下(轴上只有一个值的离散比例尺),无法使其起作用。
我尝试将其转换为数字,并使用基于this response的expand(c(0,0)。 当应用于x轴时,它有效,但不适用于y轴(可能是因为y轴上只有一个分割点?)
library(tidyverse)
df <- tibble(Site = rep("A", 4),
Basin = rep("B1", 4),
Variable = c("V1", "V2", "V3", "V4"),
cls = c("up", "down", "ns", "up"))
#basic plot (output above)
p <- ggplot(df , aes(x=Variable, y=Site)) +
geom_point(size=3, aes(color=cls, shape=cls, fill=cls)) +
facet_grid(Basin~., scales="free", space="free")
p
#attempting to convert discrete scale to continuous and apply limits to axis
p2 <- ggplot(df , aes(x=Variable, y=c(as.numeric(factor(df$Site)))) +
geom_point(size=3, aes(color=cls, shape=cls, fill=cls)) +
scale_y_continuous(limits=c(0.95,1.05),breaks=1,labels=levels(factor(df$Site)), expand=c(0,0))+
facet_grid(Basin ~ ., scales="free", space="free")
#I have also tried using
scale_y_discrete(expand=expand_scale(mult = c(0.01, .01)))
#when same method is applied to the axis it seems to work - is this because there is more than 1 break/variable
p3 <- ggplot(df , aes(x=as.numeric(df$Variable), y=as.numeric(factor(df$Site)))) +
geom_point(size=3, aes(color=cls, shape=cls, fill=cls)) +
scale_x_continuous(limits=c(0.95,4.05),breaks=seq(1:length(unique(df$Variable))),labels=levels(factor(df$Variable)),
expand=c(0,0))+
facet_grid(Basin~., scales="free", space="free")
+ theme(aspect.ratio = ...)
来调整绘图的宽度。 - yake84