0

I have a data set that lists the Top 10 web visitors. It has CustID and Visits columns. I am trying to plot a bar chart. I made the horizontal axis=True. I want the Yaxis labels to list top 10 custID from the data - so that for every new dataset the Y axis label value change.

So far, I am using this code:

barplot(WebPages$visits, 
        main="Top Visitors", 
        horiz=TRUE,
        col="dark blue")

How do I set the Yaxis labels to give the top 10 custID from the data?

Andy Clifton
  • 4,926
  • 3
  • 35
  • 47
SS_11
  • 53
  • 3
  • 7
  • 1
    Could you give us some data to play with? There are lots of things that could be done with this, and it's easier if we can give you examples. – Andy Clifton Sep 27 '13 at 03:49
  • Just add the `names.arg=WebPages$CustID` argument to your `barplot(...` call – thelatemail Sep 27 '13 at 03:57
  • SS_11, welcome to StackOverflow. There's [a great post here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) about making a reproducible example. If you can give us some sample data to play with, it'd be helpful. Common ways this are done are with the `data` command. Like `data(iris)`, now you can see the `iris` data.frame is in memory. So if you can find some data and then feed it into your `barplot`, we can help you better. – Statwonk Sep 27 '13 at 04:35

1 Answers1

2

You can write the following after calling barplot function:

axis(2, at = seq(length(WebPages$CustID)), labels = WebPages$CustID)
raymondowf
  • 31
  • 3
  • Thanks! The labels on the Y-axis are not parallel to the x axis.and therefore I am able to see only 5 CustID instead of 10 – SS_11 Sep 27 '13 at 12:48
  • Hey SS_11 nobody will be able to get exactly what you are looking for unless you can provide some working example. Use head(df) to let us see what your working with here. – Michael Cantrall Mar 11 '18 at 16:47