-4

I can't seem to figure out the command for changing the x- and y-axes to go from 200-800 in increments of 100. (new to R, don't know how to provide large amounts of data)

     SAT <- read.csv(file.choose(), header = TRUE)
    SAT2 <- na.exclude(SAT)
    SAT.MV <- SAT2[,1:2]
    plot(SAT.MV$VSAT,SAT.MV$MSAT,main="Math and Verbal SAT Scores",xlab="Verbal Score",
ylab="Math Score")
    head(SAT.MV)
    SAT.MV.3means <- kmeans(SAT.MV,centers=3)
    SAT.MV.3means$centers
    SAT.MV.3means$cluster
    plot(SAT.MV[SAT.MV.3means$cluster == 1, ], col = "red", 
         xlim=c(min(SAT.MV[ ,1]),max(SAT.MV[ ,1])),
         ylim=c(min(SAT.MV[ ,2]),max(SAT.MV[ ,2])))
    points(SAT.MV[SAT.MV.3means$cluster == 2,], col = "blue")
    points(SAT.MV[SAT.MV.3means$cluster == 3,], col = "seagreen")
    points(SAT.MV.3means$centers,pch=2, col = "black")
            plot(SAT.MV[SAT.MV.3means$cluster == 1, ], col = "red", 
             xlim=c(min(SAT.MV[ ,1]),max(SAT.MV[ ,1])),
             ylim=c(min(SAT.MV[ ,2]),max(SAT.MV[ ,2])))
        points(SAT.MV[SAT.MV.3means$cluster == 2,], col = "blue")
        points(SAT.MV[SAT.MV.3means$cluster == 3,], col = "seagreen")
        points(SAT.MV.3means$centers,pch=2, col = "black")
pmk1007
  • 1
  • 2
  • 3
    Can you please include data and/or code that will provide us with a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ? – Ben Bolker Nov 03 '16 at 22:59
  • Thanks for trying, but this is still not reproducible. We don't know what file you're reading ... If you read the link in my comment above, you'll see that "reproducible example" usually doesn't/shouldn't mean giving us **all** of your data - it means boiling your problem down to something simpler/shorter but still demonstrates your issue ... – Ben Bolker Nov 03 '16 at 23:12
  • @BenBolker As a math student, not a programmer, and having only taken one computer science class, I still am not understanding how I'm supposed to make a sample code for a huge data set. Or why that's necessary when I've provided the scale I need for the axes. I just don't know what code can change the scale of the axes. – pmk1007 Nov 03 '16 at 23:28
  • 1
    The problem with not having a reproducible example is that it makes answerers work harder (to make one up themselves so they can show/test that their answer works), and the lack of a reproducible example often conceals ambiguity in your question. That may not be true in this case, but it's why experienced SO users will insist so strongly on getting a reproducible example. – Ben Bolker Nov 03 '16 at 23:49

1 Answers1

2

Suppose I have a small data set:

dd <- data.frame(x=c(300,700,1000),y=c(-100,200,700))

I want to plot this data on a set of scales that might not match the scale of the data (that is, R's automatic rules might not work as I want).

## xlim, ylim set bounds: axes=FALSE turns off axes
plot(y~x,data=dd,xlim=c(200,800),ylim=c(200,800),axes=FALSE)

Now draw the axes manually:

ax <- seq(200,800,by=100)  ## same for both axes
axis(side=1,at=ax)         ## side=1 -> bottom
axis(side=2,at=ax)         ## side=2 -> left
box()  ## to draw the bounding box

In this example, all but one of the points in the data set are actually excluded from the plot:

enter image description here

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453