[R] [External] Error in percentage stacked barplot

Richard M. Heiberger rmh @end|ng |rom temp|e@edu
Wed May 3 15:57:17 CEST 2023


likert is built on the lattice barchart function.
Hence everything in
?panel.barchart
?xyplot
applies.  The legend is constructed with the auto.key argument.

You can move the legend to the left, but that is not a good idea for a horizontal barchart.

likert(t(hellisheidi), ReferenceZero=.5,
        xlab="X-lab", ylab="Y-lab", main="stacked bar chart",
        auto.key=list(space="left", columns=1))

Note that the legend is vertical and the plot is horizontal, making it difficult
to read both simultaneously.

Rich

> On May 3, 2023, at 04:58, Maria Lathouri <mlathouri using yahoo.gr> wrote:
>
>
> Dear Richard,
>
> Thank you very much for your reply. I went through the code and it worked. I was also able to change the colours.
>
> I was wondering if I can change the legend position; instead of being in the bottom to be on the left side.
>
> I tried the following but without any success
>
> strip = FALSE
> strip.right = TRUE
>
> likert(t(hellisheidi), ReferenceZero=.5, xlab="X-lab", ylab="Y-lab", main="Stacked bar chart", col=c("#E94E1B", "#F7AA4E", "#BEBEBE", "#6193CE", "#00508C", "#E94E1B", "#BEBEBE"), legend.position="left")
>
> Once again, thank you very much.
>
> Kind regards,
> Maria
>
>
> Στις Τρίτη 2 Μαΐου 2023 στις 08:51:16 μ.μ. GMT+1, ο χρήστης Richard M. Heiberger <rmh using temple.edu> έγραψε:
>
>
>
>
>
> ## 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