I am using the command scale_x_break
to set an axis break in a ggplot. However, the current code has way too many tick marks in the "extreme values" section after the axis break. The command contains an argument ticklabels
, however for some reason, I cannot use this to change the "extreme" tick marks, i.e., -1000, -1010, -1020, -1030, -1040, and -1050. This command however, does work well in adding/removing tick marks "before" the axis break. Case in point: the section of code ticklabels = c(-5, -1015)
adds a tick mark for -5 and removes all other tick marks before the axis break, but does not add the -1015 or remove any tick marks after the axis break.
Ideally, the "extreme" panel would have 3 tick marks: -1000, -1025, and -1050.
library(ggplot2)
library(ggbreak)
library(patchwork)
x1 <- c('A', 'B','C', 'D', 'E', 'F', 'G')
y1 <- c(-9.375783475, 6.21616158, -19.32680732, -8.727239523, 13.93210958, -1051.866122, -75.11041633)
df1 <- data.frame(x1, y1)
p1 <- ggplot(df1, aes(y1, x1)) geom_col(orientation="y")
p2 <- p1 scale_x_break(c(-1000, -80), ticklabels = c(-5, -1015)) xlab("relative variable importance") ylab("commodity network")
p2
CodePudding user response:
You can add a scale_x_continuous
with specified breaks to p2
p2 scale_x_continuous(breaks = c(-1000, -1025, -1050))