当我使用ggbreak
分割x轴时,图可以正确显示。但是,如果我指定了y轴的比例,y轴就不会像没有指定时那样显示。我该如何解决这个问题?
library(ggplot2)
library(ggbreak)
DF <- data.frame(x = 1:40,
y = c(rnorm(n = 10,
mean = 1000,
sd = 250),
rnorm(n = 10,
mean = 200,
sd = 10),
rnorm(n = 10,
mean = 1000,
sd = 250),
rnorm(n = 10,
mean = 200,
sd = 10)))
# Without log axis
ggplot(data = DF,
aes(x = x,
y = y)) +
geom_point() +
scale_x_break(breaks = c(10, 20),
scales = "free")
注意,这里y轴被打印两次,这与所期望的不同。
# With log axis
ggplot(data = DF,
aes(x = x,
y = y)) +
geom_point() +
scale_y_log10(name = "y-axis",
limits = c(0.1, 10000),
breaks = c(0.1, 1, 10, 100, 1000, 10000),
labels = c(expression(10^-1),
expression(10^0),
expression(10^1),
expression(10^2),
expression(10^3),
expression(10^4))) +
scale_x_break(breaks = c(10, 20),
scales = "free")
1条答案
按热度按时间4sup72z81#
虽然这看起来像是一个bug,但解决方法是显式指定一个重复的轴,删除
breaks
,labels
和name
: