问题描述
我想绘制一个绘图,其坐标轴与附加的图像相似.我对附件的X轴特别感兴趣.
通常,一个轴显示例如0到10.我的数据位于x轴的5-7之类的位置.所以我希望我的 25%
x轴显示 0-5
,其余的 75%
显示 5-10
.但我的意思不是像ggpplot这样的东西.
我正在使用baseR.我想图像也是使用R base创建的.
我应该如何像示例一样进行绘制?谢谢
感谢您的帮助.我添加了图片,希望这次会显示出来.
这是个好主意,但请想象这是我的数据,
X< ;-("A","B","C","D","E","F","G","H")#一些湖泊的基本名称
Y<-(0.891338,0.962008,0.929528,1.034015,0.883051,0.887387,0.795245,0.862037)
我想绘制一个图,其中x变量显示我的湖泊名称,y变量显示值.我需要使y轴从0到1.3(因为我需要在图的每个点上添加SD和一些标签;因此它需要宽敞).但是可以看出,我没有低于〜0.70的y值.因此,我希望y变量的0到0.70之间的区域仅占y轴的一小部分,例如占总数的15%.我要这样做有两个原因.a)y轴从0开始,b)因为我的y值的差异很小,我希望将这些值的实际面积定位在y轴的较大部分中,以便可以看到差异./p>
为进一步说明,我添加了我所做的第二张图片.我只需要在此图的y轴上添加0到0.7,但要在0.7之前最多显示一个间隔(并且可能显示1、2或3个标签和刻度)
再次感谢大家.你真不可思议.
根据问题的编辑内容来编辑我的帖子.
人们使用的轴是逐渐变化的,就像您显示的图像一样,它可能是记录的x轴.要考虑的第一个问题是,是否希望y轴逐渐或逐段更改.我用两种方式为您绘制了它们.
X<-c("A","B","C","D","E","F","G","H")#某些湖泊的基本名称Y< c(0.891338,0.962008,0.929528,1.034015,0.883051,0.887387,0.795245,0.862037)#连续缩放plot(1:length(X),exp(Y),#尝试将exp()更改为其他基数,以进行或多或少的缩放.ylim = exp(c(0,1.3)),xaxt ="n",yaxt ="n",xlab =湖",ylab =某物")#添加x轴标签轴(1,1:长度(X),X)#添加y轴标签轴(2,exp(seq(0,1.3,by = 0.1)),seq(0,1.3,by = 0.1),las = 1)
#分段刻度情节(1:长度(X),Y,ylim = c(0.5,1.3),#您可以调整0.5以给您更多或更少的空间来显示0到0.7之间的值xaxt ="n",yaxt ="n",#我们稍后将添加a和y轴标签xlab =湖",ylab =某物")#添加x轴标签轴(1,1:长度(X),X)#添加y轴标签#注意0到0.7的部分是假".我们只是将标签添加到0.5-0.7的间隔内,您可以将其调整为更大或更小.轴(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)#可能添加一条线以指示此处的轴发生了变化.
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.
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.
这篇关于基本r图中的不均匀轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!