我想创建一个在y轴上具有不同大小间隔的多个断点的曲线图。我能找到的最接近的帖子是这个Show customised X-axis ticks in ggplot2,但它并没有完全解决我的问题。
# dummy data
require(ggplot2)
require(reshape2)
a<-rnorm(mean=15,sd=1.5, n=100)
b<-rnorm(mean=1500,sd=150, n=100)
df<-data.frame(a=a,b=b)
df$x <- factor(seq(100), ordered = T)
df.m <- melt(df)
ggplot(data = df.m, aes(x = x, y=value, colour=variable, group=variable)) +
geom_line() + scale_y_continuous(breaks = c(seq(from = 0, to = 20, by = 1),
seq(from = 1100, to = max(y), by = 100))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
问题是如何使第一组中断与第二组中断成比例(因此是可见的)。
任何指针都将非常感谢,谢谢!
发布于 2015-02-02 13:14:18
您可以尝试如下所示:
# Rearrange the factors in the data.frame
df.m$variable <- factor(df.m$variable, levels = c("b", "a"))
ggplot(data = df.m, aes(x = x, y=value, colour=variable, group=variable)) +
geom_line() + facet_grid(variable~., scales = "free")
希望这能有所帮助
https://stackoverflow.com/questions/28278179
复制相似问题