开发者

R plot graphs with large numbers

开发者 https://www.devze.com 2023-02-26 01:41 出处:网络
I am using R and have an array with data values ranging from 600-225,000. I can plot it just fine, but the labels for the tick marks cover up the label for开发者_StackOverflow中文版 the axis.

I am using R and have an array with data values ranging from 600-225,000. I can plot it just fine, but the labels for the tick marks cover up the label for开发者_StackOverflow中文版 the axis.

Right now the code is:

g_range=range(0,list)
plot(list, axes=FALSE, ylab="Total")
axis(2, at=15000*0:g_range[2])

I just want to be able to see the values and the label


To give you more room, rotate the y-axis axis-labels 90 degrees and move the y-axis description out a line or two:

 #Generate the data
 list<-exp(seq(log(600), log(225000), length.out=10))
 g_range=range(0,list)

 #Setup the plotting area and plot it
 par(plt=c(0.2, 0.9, 0.2, 0.9))
 plot(list, axes=FALSE, xlab="", ylab="")

 #Plot the x-axis
 axis(1)
 mtext("Index", side=1, line=2)

 #Plot the y-axis     
 axis(2, las=2)
 mtext("Total", side=2, line=5)


I like to use ggplot2 when I have a lot of values because it's easy to set the opacity of your dots. For example, this makes it so that you need 20 overlapping points to get a black spot. It's pretty neat. ggplot2 also has sensible defaults for setting axis labels, so you shouldn't have to worry about it too much.

library(ggplot2)
dat <- data.frame(x1=rnorm(150000), x2=rnorm(150000))
ggplot(dat, aes(x1,x2))+geom_point(alpha=0.05)
0

精彩评论

暂无评论...
验证码 换一张
取 消