Subhabrata
2006-Feb-16 03:50 UTC
[R] R-help - Problem in drawing braplot with a huge value of data
Hello R-experts, I am facing a strange problem while creating a barplot. I have serise of data of which the first on is around 162589 while the remaining data are around 0-150. so when I am ploting the barplot with all the data I am getting a single line -> test1.jpg. But If I remove the 1st value i.e 162589 then I am getting a normal barplot -> test2.jpg Can some one help me regarding this matter. Thank you for any help. Regards Subhabrata
Marc Schwartz
2006-Feb-16 04:50 UTC
[R] R-help - Problem in drawing braplot with a huge value of data
On Thu, 2006-02-16 at 09:20 +0530, Subhabrata wrote:> Hello R-experts, > > I am facing a strange problem while creating a barplot. I have serise of > data of which the first > on is around 162589 while the remaining data are around 0-150. so when I am > ploting the barplot > with all the data I am getting a single line -> test1.jpg. > > But If I remove the 1st value i.e 162589 then I am getting a normal > barplot -> test2.jpg > > Can some one help me regarding this matter. > > Thank you for any help. > > Regards > > SubhabrataYou have a wide range for your data, so the smaller values are getting lost. You can try to use a log scale on the y axis and then set the tick marks to reasonable values: # Do the barplot, setting 'log = "y"' to use a log # scale. # Set the range of the y axis to nice values. Note of # course that you cannot have 0 since log10(0) = -Inf # Also set the y axis so that the tick marks are not # drawn here barplot(c(162589, 50, 100, 150), log = "y", ylim = c(1, 200000), yaxt = "n") # Use axTicks to get 'nice' values for the tick marks # The 'y' axis is '2' at <- axTicks(2) # Now use axis() to set the tick mark values and use # 'las' to make the labels horizontal # Use sprintf() to force non "1e+XX" labels axis(2, at = at, label = sprintf("%d", at), las = 2) You can then add further annotation as you require. If you would prefer nicer 10^x exponential notations where the exponent is superscripted for the y axis tick marks, you could use 'plotmath' and do something like this: barplot(c(162589, 50, 100, 150), log = "y", ylim = c(1, 200000), yaxt = "n") at <- axTicks(2) axis(2, at = at, labels = parse(text = paste("10 ^", log10(at))), las = 2) The final line uses parse() to create math expressions for the tick mark notations. The result of the paste() call is:> paste("10 ^", log10(at))[1] "10 ^ 0" "10 ^ 1" "10 ^ 2" "10 ^ 3" "10 ^ 4" "10 ^ 5" These are then converted into expressions using parse() that can be drawn on the axis by plotmath. See ?axis, ?axTicks, ?sprintf, ?plotmath, ?parse and ?paste for more information here. HTH, Marc Schwartz