R &引用;“无单位”;,定性或相对轴比例ggplot2
假设我有下面的图表R &引用;“无单位”;,定性或相对轴比例ggplot2,r,ggplot2,R,Ggplot2,假设我有下面的图表 dat <- data.frame(x = 1:10, y = 1:10) ggplot(dat, aes(x=x, y=y)) + geom_point() dat像这样的东西可能会有帮助 dat <- data.frame(x = 1:10, y = 1:10) p <- ggplot(dat, aes(x=x, y=y)) + geom_point() + scale_x_continuous('', breaks=NULL)+ scal
dat <- data.frame(x = 1:10, y = 1:10)
ggplot(dat, aes(x=x, y=y)) + geom_point()
dat像这样的东西可能会有帮助
dat <- data.frame(x = 1:10, y = 1:10)
p <- ggplot(dat, aes(x=x, y=y)) + geom_point() +
scale_x_continuous('', breaks=NULL)+
scale_y_continuous('', breaks=NULL)
g <- ggplotGrob(p)
library(gtable)
library(grid)
my_axis <- function(low="low", high="high", axis=c("x", "y"), ...){
axis <- match.arg(axis)
if(axis == "x"){
g1 <- textGrob(low, x=unit(0,"npc"), hjust=0)
g3 <- textGrob(high, x=unit(1,"npc"), hjust=1)
g2 <- segmentsGrob(grobWidth(g1) + unit(2,"mm"), unit(0.5,"npc"),
unit(1,"npc") - grobWidth(g3)- unit(2,"mm"),
unit(0.5,"npc"), ...)
} else if(axis == "y"){
g1 <- textGrob(low, y=unit(0,"npc"), rot=90, hjust=0)
g3 <- textGrob(high, y=unit(1,"npc"), rot=90, hjust=1)
g2 <- segmentsGrob(unit(0.5,"npc"),grobHeight(g1) + unit(2,"mm"),
unit(0.5,"npc"),
unit(1,"npc") - grobHeight(g3)- unit(2,"mm"),
...)
}
grobTree(g1,g2,g3)
}
g <- gtable_add_grob(g, my_axis(arrow=arrow(length=unit(2,"mm"))),
t=nrow(g)-2, b=nrow(g)-1, l=4)
g <- gtable_add_grob(g, my_axis(axis="y", arrow=arrow(length=unit(2,"mm"))),
t=3, l=1,r=3)
grid.newpage()
grid.draw(g)
dat作为替代方案,由于您确实要求“低-->高”,这里有一个选项不涉及分解绘图
dat+1,但我必须在textGrob
中手动指定水平位置。我更喜欢这样一种解决方案,即数值dat
的更改不需要其他更改。这些位置实际上是以“npc”单位表示的,即“标准化父坐标”,即我认为您想要的。@baptiste:这似乎被打破了。