Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Plot the name.arg above the chart instead of the default value below

I´ve been trying to change the name of the variables in the barplot() from the bottom of the chart to the top, but didn’t find how to do it so far.

The code I have is as follows:

    matrix(c(1, 0, 0, 0, 0.9375, 0.0625, 0, 0, 1, 0, 0, 0, 0.8125, 0.0625, 0.125, 0, 0.75, 0.1875, 0, 0.0625, 0.625, 0.125, 0.875, 0.0625, 0.5, 0.125, 0.125,0.25), 4, 7)
    barplot(matriz_plot,  col=c("red","white"), col.axis="blue", border="black",ylim =c(0, 4))       

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Also, I have trouble to plot the bars as they should be. In my plot, variables 1, 2, 3, and 4 are stacked, but I would like to show them at their level.
The plot I am looking for, is rather this one:
enter image description here

Thanks a lot for your help!

>Solution :

You can do it this way:

mat <- apply(matriz_plot, 2, function(x) c(rbind(x, 1-x)))
bp <- barplot(mat, col=c("red", "white"), col.axis="blue", 
              border="black", ylim=c(0, 4))       
mtext(paste0("S", seq_along(bp)), at=bp, col="blue", line=.5)

barplot

The first line (apply) computes the reciprocal for each value in your matrix and merges it with the original values (by columns) so that you can simply use barplot to plot it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading