问题
I want to have a plot the axes of which be similar to attached images. I am particularly interested in the X axis of the attachment.
Generally, an axis that shows for example 0 to 10. My data are located somewhere like 5-7 of the x axis. So I want my 25%
x axis to show 0-5
and the rest 75%
to show 5-10
. But I do not mean something like ggpplot.
I am working with base R. and the image is also created with R base, i guess.
How should I make a plot like the example? Thank you
Thank you for your help. I added the image, hopefully this time it will show up.
That was a good trick but imagine this is my data,
X <- ("A", "B", "C", "D", "E", "F", "G", "H") #Basically names of some lakes
Y <- (0.891338, 0.962008, 0.929528, 1.034015, 0.883051, 0.887387, 0.795245, 0.862037)
I want to have a plot with x variables showing my lakes' names, and y variable showing the values. I need to have a y axis going from 0 to 1.3 (because I need to add SD and some labels to each point on graph; so it needs to be roomy). But as can be seen, I do not have y values below ~ 0.70. So I want the area between 0 to 0.70 of my y variable to form only a small portion of my y axis, say 15% of the total. I want to do this because of 2 reasons. a) y axis starting from 0, b) because the differences in my y values are small, I want the actual area these values are going to be located to be shown in bigger portion of y axis so that the differences can be seen.
To clarify it more, I added a second image of what I have made. All I need is to add 0 to 0.7 to y axis on this graph but to be shown only as a much as one interval before 0.7 (and probably with 1, 2 or 3 labels and ticks)
Thanks again guys. You're incredible.
回答1:
Editing my post based on the edits of the question.
People using an axis that is gradually changing, like the image you showed, which is probably a logged x-axis. The first question to think about is that if you want your y-axis to change gradually, or piece-wise. I plotted them in both ways for you.
X <- c("A", "B", "C", "D", "E", "F", "G", "H") #Basically names of some lakes
Y <- c(0.891338, 0.962008, 0.929528, 1.034015, 0.883051, 0.887387, 0.795245, 0.862037)
# continuously scaling
plot(1:length(X), exp(Y), # try changing exp() to other base for more or less scaling.
ylim = exp(c(0, 1.3)), xaxt = "n", yaxt = "n",
xlab = "Lakes", ylab = "Something")
# add x-axis label
axis(1, 1:length(X), X)
# add y-axis label
axis(2, exp(seq(0,1.3, by = 0.1)),
seq(0,1.3, by = 0.1), las =1)
# Piece-wise scale
plot(1:length(X), Y,
ylim = c(0.5, 1.3), # you could adjust 0.5 to give you more or less room to show values between 0 to 0.7
xaxt = "n", yaxt = "n", # we will add a and y-axis label later
xlab = "Lakes", ylab = "Something")
# add x-axis label
axis(1, 1:length(X), X)
# add y-axis label
# note that 0 to 0.7 part is "fake". We just add labels to 0.5-0.7 interval, which you could adjust to being bigger or smaller.
axis(2, c(seq(0.5,to = 0.7, length.out=8), seq(0.8,1.3, by = 0.1)),
c(seq(0, 0.7, length.out = 8), seq(0.8,1.3, by = 0.1)), las = 1)
abline(h = 0.7, lty = 3) # maybe add a line to indicate that axis changes here.
来源:https://stackoverflow.com/questions/58548075/uneven-axis-in-base-r-plot