Search code examples
rplotaxis-labels

Change Y label values to whole numbers


I am making barcharts and accidentally changed a default setting. Previously, the code resulted in the y values as whole numbers (1), but now displays as float/integers (1.0). I want to display whole numbers only.

data = rbind(c(1,2), c(2,1), c(3,0), c(4,3))
headers = c("bin", "rank")
colnames(data) = headers
View(data)

barplot(data$rank, main="First Control", horiz=FALSE, las =1 , ylab = "Use Rank",
        names.arg = data$bin)

enter image description here


Solution

  • Add ylim=c(0,4) to your code:

    barplot(data$rank, ylim=c(0,4), main="First Control", horiz=FALSE, las =1 , ylab = "Use Rank",
            names.arg = data$bin)
    

    Output: enter image description here