In barplot, is it possible to make the labels parallel to the bars?
Suppose we have the data frame called "data".
Page PV UniquePgv 1 /photos/upcoming 5295 2733 2 / 4821 2996 3 /search 1201 605 4 /my_photos 827 340 5 /photos/circle 732 482
I want to make a barplot of PV with the Page column as the label.
names <-data$Page barplot(data$PV,main="Page Views", horiz=TRUE,names.arg=names)
Which Produces:
The name of each bar is vertical, while the bars are horizontal.
How can I make the labels display horizontally and parallel with the bars? If it is not possible, I am open to suggestions for other ways to plot this information.
To add labels on top of each bar in Barplot in R we use the geom_text() function of the ggplot2 package. Parameters: value: value field of which labels have to display. nudge_y: distance shift in the vertical direction for the label.
Horizontal Bar Chart Horizontal bar charts are often used to represent comparisons between nominal variables. With this tool, you can display long data labels using horizontal rectangles and still have enough room for textual information.
To create a horizontal bar chart using ggplot2 package, we need to use coord_flip() function along with the geom_bar and to add the labels geom_text function is used. These two functions of ggplot2 provides enough aesthetic characteristics to create the horizontal bar chart and put the labels at inside end of the bars.
You can use the las
graphics parameter. However, if you do that, the names will run off the end of the window, so you need to change the margins. For example:
par(mai=c(1,2,1,1)) barplot(data$PV,main="Page Views", horiz=TRUE,names.arg=names,las=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With