0

I googled but can't find an answer to my problem. I have some dates:

  • date for temperature (region at 30 to 60 gr Celsia)
  • date for consumption in Watt (region at 100 to 160 Watt)
  • date for frequency in GHz (region at 1.2 to 3.1 GHz)

Then I plot these dates in one graphic I cant see different in frequency (it so small).

How add to axis ticks like 1.2 to 3.1 with step 0.1 and after return to step 10?

And how to add scale for region like 1.2 to 3.1 (it will be so big as step with 10 else I cant see. Step ticks it so small) and after return to scale normal for step 10 ?

I wont focusing in some regions of axis add some scale for focused region.

P.S. I can do this in gnuplot if set multi axis but I want to try it in R.

P.S. P.S. sorry for English

library(ggplot2)
s=matrix(0,10,4);
s[1:10,1]=1:10;
s[1:10,2]=1.2:3.1;
s[1:10,3]=70:79;
s[1:10,4]=150:159;
colnames(s) = c("time", "freq", "temp", "power");
ggplot(data=NULL, aes(x=s[,1], ) ) +
    geom_line( aes(y=s[,3], color="blue") )  +
    geom_line( aes(y=s[,4], color="red") )  +
    geom_line( aes(y=s[,2], color="green") ) +
    scale_y_continuous(breaks=c(1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.1,4,6,8,10) );
Sam
  • 7,252
  • 16
  • 46
  • 65
Black S.
  • 19
  • 5
  • Welcome to SO. People will (and can) help you a lot better if you provide them with a clear illustration of your problem. Please read the faq on how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). It requires a bit more effort from you, but I can tell you from experience that it's worth the extra effort. – Jaap Apr 27 '14 at 06:26

1 Answers1

0

The 'problem' with your data is that the freq, temp & power variables have very different scales. As a result the variation in especially the freq variable can hardly be seen when you combine them all in one plot. Moreover, for the other two variables the development over time is hard to see as weel.

In this case it's probably wiser to use a faceted plot:

# transforming the data into a dataframe of the long format
df <- as.data.frame(s)
require(reshape2)
df2 <- melt(df, id="time")

# creating the plot
ggplot(df2, aes(x=time, y=value, color=variable)) +
  geom_line() +
  facet_grid(variable ~., scales="free_y")

the result: enter image description here

Jaap
  • 81,064
  • 34
  • 182
  • 193
  • I already tried scale_y_continuous(breaks= but it do range between ticks (1.2, 1.3, 1.4 ... 3.1) so small. – Black S. Apr 27 '14 at 06:33
  • Can scale_y_log set different scale in different range of axis ? – Black S. Apr 27 '14 at 06:34
  • You can define the breaks in `scale_y_log10` in the same way as in `scale_y_continuous`. – Jaap Apr 27 '14 at 06:36
  • sorry, forgot to add, tried scale_y_log10 but it not so good for me It will be great if i will be have linear scale (not log or log10) – Black S. Apr 27 '14 at 06:37
  • Did you see my comment to the question? It would be helpful if added the code you already tried and some example data. That will make it a lot easier for me to help you. – Jaap Apr 27 '14 at 06:40
  • Thanx for posting the data, see my updated answer. Does this solve your problem? – Jaap Apr 27 '14 at 16:39
  • I nub in R and and every time then I do a graph I have dilemma - or familiar bash + gnuplot or new ggplot/plot in R. I considered as ggplot is very flexible visualizer. It would be great of course solve the problem with a different scale, but at the moment faset_grid solves my problem. I also tried it with faset_grid, but did not know about the function of MELT. Thanks for the informative answer. – Black S. Apr 27 '14 at 17:14
  • When you want to know more about using `ggplot2`, I can recommend the [graph section of Cookbook for R](http://www.cookbook-r.com/Graphs/) – Jaap Apr 27 '14 at 19:05
  • Thanks. I already download this book. Its very helpful but some aspect like this I cant found in this book. – Black S. Apr 28 '14 at 15:34