Label does not appear on the chart

Asked

Viewed 466 times

1

Hello,

My configuration is as follows::

> sessionInfo()

R version 3.3.1 (2016-06-21)

Platform: x86_64-W64-mingw32/x64 (64-bit)

locale: _LC_COLLATE=Portuguese_Brazil.1252_, _LC_CTYPE=Portuguese_Brazil.1252_, _LC_MONETARY=Portuguese_Brazil.1252_, _LC_NUMERIC=C_ and _LC_TIME=Portuguese_Brazil.1252_

Attached base Packages: Stats, Graphics, grDevices, utils, datasets, methods and groundwork

I’m drawing up some graphs and, in particular, I’m picking up a Barplot with the following code:

    ## ClienteUF
var_check = mydata$ClienteUF
mytable<-table(var_check)

freq(var_check,main="Unidade da Federação",plot = FALSE)
#Fitting Labels
par(las=2) # make label text perpendicular to axis
par(mar=c(4,4,2,2)) # increase y-axis margin.
percentlabels<- round(100*table(var_check)/sum(table(var_check)), 1)
barlabels<- paste(percentlabels, "%", sep="")

graphlabels <- 
  barplot(table(var_check), main="Unidade da Federação",cex.names=0.7, 
          names.arg = names(mytable), yaxp=c(0,max(mytable)+5,5),
          las = 1)
## Add text at top of bars
text(x = xx, y = mytable, label = barlabels, pos = 3, cex = 0.8, col = "red")

The graph shown is this: inserir a descrição da imagem aqui

Does anyone know how to make the label appear on the SP bar?

1 answer

2


Your example is not reproducible, because we do not have access to your data. I imagine that increasing the limit of the axis y solves your problem:

barplot(table(var_check), main="Unidade da Federação",cex.names=0.7, 
      names.arg = names(mytable), yaxp=c(0,max(mytable)+5,5),
      las = 1, ylim=c(0, 110))

I don’t know if 110 is the best value for your chart. So change the upper limit of the argument ylim=c(0, 110) to make your chart more aesthetically beautiful. The best way to do this, I believe, is by trial and error.

  • 1

    Thanks @Marcus, that’s right :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.