0

I am plotting some values (y) across a continuous variable (window) but I would like to change the values on the x-axis to a value class variable (chr) that works as a group variable (one 'chr' value for many 'window' values).

This is an example of the data with my code:

chr<-c(1,1,1,1,1,2,2,2,2,2)
window<-c(1,2,3,4,5,6,7,8,9,10)
y<-c(2,0.5,3,2.5,2,0.2,0.3,0.7,0.3,6)

data <-data.frame(as.character(chr),window,y)

ggplot(data,aes(window,y),coulour=chr)+ geom_point(color=data$chr)

I want to plot the 'y' values agains the 'window' values, but I don't want to see 'window' values on my x-axis - I want to see one (01) 'chr' value that represent all 'window' values for that given 'chr'.

For example, if you run the code above, you'll see the values "2.5", "5.0", "7.5", and "10.0", BUT, I would like to see one "1" for those 'y' values from "0" to "5.0" and one "2" for those 'y' values from "5.0" to "10.0".

Any ideas? Thanks!

tonytonov
  • 25,060
  • 16
  • 82
  • 98
NickSerao
  • 33
  • 4
  • Now that I think of it, this is probably a [duplicate](http://stackoverflow.com/questions/5096538/customizing-the-axis-labels-in-ggplot) – David Arenburg Jun 19 '14 at 22:11

1 Answers1

0

use scale_x_discrete

chr<-c(1,1,1,1,1,2,2,2,2,2)
window<-c(1,2,3,4,5,6,7,8,9,10)
y<-c(2,0.5,3,2.5,2,0.2,0.3,0.7,0.3,6)

data <-data.frame(chr,window,y)
library(ggplot2)
ggplot(data,aes(window,y),coulour=chr)+ geom_point(color=data$chr) + 
scale_x_discrete(breaks = 1:10, labels=chr)

enter image description here

David Arenburg
  • 91,361
  • 17
  • 137
  • 196