I want to get a broken X-axis in my plot. In the x-axis I like to insert a broken-axis symbol < // >
[starting from 2 and ended in end 8 which means 2-8 will be hidden in < // >
symbol] so the other values can be emphasized. In Matlab, this task is performed by using BreakXAxis. In R, plotrix library helps only to plugin a break-axis symbol, that's all.
x <- c(9.45, 8.78, 0.93, 0.47, 0.24, 0.12)
y <- c(10.72, 10.56, 10.35, 10.10, 9.13, 6.72)
z <- c(7.578, 7.456, 6.956, 6.712, 4.832, 3.345)
plot(x, y, col='blue', pch=16, xlab= 'x', ylab='y, z')
points(x, z, col='red', pch=17)
library(plotrix)
axis.break(1,2,style="slash")
In the x-axis I like to insert a broken-axis symbol < // > [starting from 2 and ended in end 8 which means 2-8 will be hidden in < // > symbol] so the other values can be emphasized. In Matlab, this task is performed by using BreakXAxis. In R, plotrix library helps only to plugin a break-axis symbol, that's all.
You can also insert an axis break when you have outliers or extreme values in your data. In this bubble chart, New York has significantly higher real estate costs, so an X axis break allows you to keep it on the chart while still allowing plenty of space for the other cities.
Methodn1: Break Y-Axis of Plot Using gap. plot() Function of plotrix Package. In this method break y-axis of the plot using the gap. plot() Function of plotrix Package, the user first needs to install and import the plotrix package to the working console of the R, further the user needs to call the gap.
When we create a plot in R, the Y-axis labels are automatically generated and if we want to remove those labels, the plot function can help us. For this purpose, we need to set ylab argument of plot function to blank as ylab="" and yaxt="n" to remove the axis title.
Sounds like you need gap.plot
library(plotrix)
par(bty="n") # deleting the box
gap.plot(x,y, gap=c(2,7.5), gap.axis="x", pch=16,
col="blue", ylim=range(c(y,z)),
xtics=c(0:3,8:10), xticlab=c(0:3,8:10))
gap.plot(x,z, gap=c(2,7.5), gap.axis="x", pch=17,
col="red", ylim=range(c(y,z)), add=TRUE); axis(2)
abline(v=seq(1.99,2.09,.001), col="white") # hiding vertical lines
axis.break(1,2,style="slash") # plotting slashes for breakpoints
xgap <- ifelse(x > 8, x-6, x)
#Possibly you'd want to check if there are values between 2 and 8.
plot(xgap, y, col='blue', pch=16, xlab= 'x', ylab='y, z', xaxt="n")
points(xgap, z, col='red', pch=17)
xat <- pretty(xgap)
xat <- xat[xat!=2]
xlab <- ifelse(xat>2, xat+6, xat)
axis(1,at=xat, labels=xlab)
library(plotrix)
axis.break(1,2,style="slash")
Don't do this. gap.plot
provides a slightly better alternative, but I would probably use facets, e.g., with ggplot2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With