[R] [External] Error in percentage stacked barplot

Richard M. Heiberger rmh @end|ng |rom temp|e@edu
Tue May 2 21:51:11 CEST 2023


## you may need to install HH
install.packagess("HH")

library(HH)

hellisheidi <- read.table(text="
Component      Sample1      Sample2      Sample3
CaO                    45                52                48
SiO2                   25                22                18
Al2O3                 15                11                14
TiO2  		      6                  5                6
Na2O                    5                  4                5
CuO                      3        3                5
Cl                         1                  3                4"
, header=TRUE, row.names="Component")

likert(t(hellisheidi), ReferenceZero=.5,
       xlab="X-lab", ylab="Y-lab", main="Stacked bar chart")


> On May 2, 2023, at 15:23, Maria Lathouri via R-help <r-help using r-project.org> wrote:
> 
> Dear all, 
> I am trying to plot the following table in stacked barplot in percentages and also horizontal.
> Component      Sample 1      Sample 2      Sample 3CaO                    45                52                48SiO2                   25                22                18Al2O3                 15                11                14TiO2                     6                  5                6      Na2O                    5                  4                5CuO                      3                  3                5         Cl                         1                  3                4
> When I tried the following functionbarplot(data,
> +         main = "Stacked bar chart",
> +         sub = "Subtitle",
> +         xlab = "X-lab",
> +         ylab = "Y-lab",
> +         axes = TRUE, horiz = TRUE)
> I got the following error
> Error in barplot.default(hellisheidi, main = "Stacked bar chart", sub = "Subtitle",  : 
>  'height' must be a vector or a matrix
> I also tried barplot(as.matrix(hellisheidi)) but what I was getting was the three stacked columns for Samples 1, 2 and 3 but I was getting an empty column for Component, instead of being the variable in the Samples. 
> 
> 
> I was hoping if you could help me on that. 
> Thank you very much in advance. 
> Kind regards,Maria
> 
> 
> 
> <1683055323500blob.jpg>______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list