0

I can't read my y-axis since is has a lot of values. 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.

But the length of the values are 1000, so I guess the range suggested above doesn't work (?). 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.

Maybe I'm missing in some simple concept, I tried to search and read R Graphics Cookbook, but without success for now.

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

Smrow
  • 89
  • 7
  • 1
    Google search term `ggplot2 axis breaks` will give you http://www.sthda.com/english/wiki/ggplot2-axis-ticks-a-guide-to-customize-tick-marks-and-labels, http://stackoverflow.com/questions/11335836/increase-number-of-axis-ticks-in-ggplot2, http://stackoverflow.com/questions/17764140/ggplot2-customised-x-axis-ticks, and many more... – Roman Aug 04 '16 at 07:21

1 Answers1

1

You are almost there.. Since your y-axis is a continuous value, you need to use scale_y_continuous instead of scale_y_discrete.

myUglyPlot <- myUglyPlot + scale_y_continuous(breaks = labels)
Deena
  • 5,925
  • 6
  • 34
  • 40
  • Is it really a continuous value? It's not a continuous mathematically speaking? Or am I wrong? Also i get this `Discrete value supplied to continuous scale` when I do as you say, I tried it before :) – Smrow Aug 04 '16 at 08:07
  • 1
    @Smrow Your example dataset has `temp` as a numeric variable, and so using a continuous scale instead of a discrete scale should work fine (and does on your example of `myUglyPlot`). – aosmith Aug 04 '16 at 14:28
  • Thanks a lot, I think I now my problem, In my "real data" in my code, I have strings and not numeric data, since it read from a file. Now it does work as you say @Dee. Sorry for not realizing this before, clumpsy of me. Thanks you too, aosmith ! – Smrow Aug 05 '16 at 12:13