简体   繁体   English

ggplot2 R,在轴上固定很多值(线图)

[英]ggplot2 R, Fixing much values in axis (Line-plot)

I can't read my y-axis since is has a lot of values. 我的y轴值很多,因此无法读取。 I tried rotating it and it doesn't work like I want, neither is it something I want to do. 我尝试旋转它,但它并没有按照我的意愿工作,也不是我想做的事情。

I want to specify the values in the axis, to be from say 20 to 30, maybe with step 0.1. 我想在轴上指定值,例如从20到30,也许使用步骤0.1。

But the length of the values are 1000, so I guess the range suggested above doesn't work (?). 但是值的长度是1000,所以我猜上面建议的范围不起作用(?)。 Ex: 例如:

runNumbers <- seq(from = 1, to = 1000)
tempVector <- seq(from = 20.0010, to = 30, by = 0.01) 
plotData   <- data.frame(RunNumber = runNumbers, temp = tempVector,
myUglyPlot <- ggplot(data = plotData, mapping = aes(x = RunNumber, y = temp, group = 1)) +      geom_line() 
#
#http://stackoverflow.com/questions/14428887/overflowing-x-axis-ggplot2?noredirect=1&lq=1 
require(scales) # for removing scientific notation
# manually generate breaks/labels
labels                   <- seq(from = 0, to = 30, length.out = 1000)
# and set breaks and labels    
myUglyPlot <- myUglyPlot + scale_y_discrete(breaks = labels, labels = as.character(labels))
# And now my graph is without labels, why?

Is there another way to do this, without rotating my labels? 还有另一种方法,而无需旋转标签吗? Or am I doing something wrong in the code from the other question (I tried to follow what he did...)? 还是我在另一个问题的代码中做错了(我试图遵循他的所作所为...)?

Later I will have 10 000 values instead, so I really need to change this, I want to have a readable axis, that I can put the interval in. 以后我将有10000个值,所以我确实需要更改此值,我想有一个可读的轴,以便可以输入间隔。

Maybe I'm missing in some simple concept, I tried to search and read R Graphics Cookbook, but without success for now. 也许我缺少一些简单的概念,但我尝试搜索和阅读《 R Graphics Cookbook》,但目前没有成功。

Thanks for your time. 谢谢你的时间。

Update Im trying to use breaks, thanks for the help guys. 更新我正在尝试使用休息时间,感谢您的帮助。 Here's what I'm doing now (only this): 这是我现在正在做的事情(仅此):

myUglyPlot   <- ggplot(data = plotData, mapping = aes(x = RunNo, y = t_amb, group = 1)) + geom_line()
myUglyPlot   <- myUglyPlot + scale_y_discrete(breaks=seq(from = 1, to = 50, by = 0.01))

But my it doesn't give me any breaks. 但是我不会给我任何休息。 See pic. 见图片。

myUglyPlot

您几乎要在那里了。由于y轴是一个连续值,因此需要使用scale_y_continuous而不是scale_y_discrete

myUglyPlot <- myUglyPlot + scale_y_continuous(breaks = labels)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM