我想制作一个在y = 0时反转y轴和x轴的图形.y轴与scale_y_reverse相反,但x轴保持在底部.
p <- ggplot(df, aes(x= conc, y=depth, group=factor(stn), color=factor(stn)))+
geom_point(shape=1)+
geom_path(alpha=0.5)+
scale_y_reverse(limits=(c(20,0)), expand=c(0,0))+
scale_x_continuous(expand=c(0,0))
Run Code Online (Sandbox Code Playgroud)
我尝试过这个帖子中的代码,如下所示,但没有用.
p +
scale_x_continuous(guide = guide_axis(position = "top")) +
scale_y_continuous(guide = guide_axis(position = "right"))
Run Code Online (Sandbox Code Playgroud)
我不需要有两个x轴,只需从底部移动到顶部.
这在 中仍然是不可能的,但在将语法与管道结合在一起ggplot2
的 中是可能的。只需使用该功能将轴放在顶部即可。ggvis
ggplot2
dplyr
add_axis
# sample data
N <- 20
df <- data.frame(conc = seq(0, N),
depth = runif(N+1, 0, 20),
stn = rep(1:4, length=N+1))
# ggplot version
require(ggplot2)
p <- ggplot(df, aes(x= conc, y=depth, group=factor(stn), color=factor(stn)))+
geom_point(shape=1)+
geom_path(alpha=0.5)+
scale_y_reverse(limits=(c(20,0)), expand=c(0,0))+
scale_x_continuous(expand=c(0,0))
p
# ggvis version
require(ggvis)
df %>% transform(stn = factor(stn)) %>%
ggvis(x = ~conc, y = ~depth, stroke = ~stn) %>%
layer_points(shape := "circle", fill := "white") %>%
layer_lines(opacity := 0.5) %>%
scale_numeric("y", reverse=TRUE, domain=c(0,20), expand=c(0,0)) %>%
scale_numeric("x", expand=c(0,0)) %>%
add_axis("x", orient = "top")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4884 次 |
最近记录: |