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 -------------- next part -------------- A non-text attachment was scrubbed... Name: 1683055323500blob.jpg Type: image/png Size: 11610 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20230502/e508c126/attachment.png>
Richard M. Heiberger
2023-May-02 19:51 UTC
[R] [External] Error in percentage stacked barplot
## 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 at 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 at 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.