Hello,
I am trying to make a stacked barplot with different behaviours ("inactive", "active", "foraging" etc) on different substrates ("tree", "ground" etc). I have found this function: # Stacked Bar Plot with Colors and Legend counts <- table(mtcars$vs, mtcars$gear) barplot(counts, main="Car Distribution by Gears and VS", xlab="Number of Gears", col=c("darkblue","red"), legend = rownames(counts)) But don't know how to apply it. Can anybody help me apply the function to work with my variables ( I can send more information if necessary, or make any clarifications). This is a great help, thanks a lot. [[alternative HTML version deleted]] ______________________________________________ [hidden email] 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. |
install.packages("HH")
library(HH) ?likert From your description, I think your data is set up to work with likert() ________________________________________ From: R-help <[hidden email]> on behalf of Areti Panopoulou <[hidden email]> Sent: Wednesday, March 10, 2021 13:29 To: [hidden email] Subject: [External] [R] Help please Hello, I am trying to make a stacked barplot with different behaviours ("inactive", "active", "foraging" etc) on different substrates ("tree", "ground" etc). I have found this function: # Stacked Bar Plot with Colors and Legend counts <- table(mtcars$vs, mtcars$gear) barplot(counts, main="Car Distribution by Gears and VS", xlab="Number of Gears", col=c("darkblue","red"), legend = rownames(counts)) But don't know how to apply it. Can anybody help me apply the function to work with my variables ( I can send more information if necessary, or make any clarifications). This is a great help, thanks a lot. [[alternative HTML version deleted]] ______________________________________________ [hidden email] 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. ______________________________________________ [hidden email] 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. |
In reply to this post by bini267
Hello,
Please read the posting guide at the end of this and every R-Help mail. You should post the output of dput(data) or, if the data set 'data' is too big, the output of dput(head(data, 20)) for us to be able to help you. Rui Barradas Às 18:29 de 10/03/21, Areti Panopoulou escreveu: > Hello, > > I am trying to make a stacked barplot with different behaviours > ("inactive", "active", "foraging" etc) on different substrates ("tree", > "ground" etc). I have found this function: > > # Stacked Bar Plot with Colors and Legend > counts <- table(mtcars$vs, mtcars$gear) > barplot(counts, main="Car Distribution by Gears and VS", > xlab="Number of Gears", col=c("darkblue","red"), > legend = rownames(counts)) > > But don't know how to apply it. Can anybody help me apply the function to > work with my variables ( I can send more information if necessary, or make > any clarifications). > > This is a great help, thanks a lot. > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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. > ______________________________________________ [hidden email] 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. |
In reply to this post by Richard M. Heiberger
> counts <- with(mtcars, table(gear, vs))
> counts vs gear 0 1 3 12 3 4 2 10 5 4 1 > likert(counts) > If this isn't enough, ask a more specific question. ________________________________________ From: R-help <[hidden email]> on behalf of Richard M. Heiberger <[hidden email]> Sent: Wednesday, March 10, 2021 17:58 To: Areti Panopoulou; [hidden email] Subject: Re: [R] [External] Help please install.packages("HH") library(HH) ?likert From your description, I think your data is set up to work with likert() ________________________________________ From: R-help <[hidden email]> on behalf of Areti Panopoulou <[hidden email]> Sent: Wednesday, March 10, 2021 13:29 To: [hidden email] Subject: [External] [R] Help please Hello, I am trying to make a stacked barplot with different behaviours ("inactive", "active", "foraging" etc) on different substrates ("tree", "ground" etc). I have found this function: # Stacked Bar Plot with Colors and Legend counts <- table(mtcars$vs, mtcars$gear) barplot(counts, main="Car Distribution by Gears and VS", xlab="Number of Gears", col=c("darkblue","red"), legend = rownames(counts)) But don't know how to apply it. Can anybody help me apply the function to work with my variables ( I can send more information if necessary, or make any clarifications). This is a great help, thanks a lot. [[alternative HTML version deleted]] ______________________________________________ [hidden email] 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. ______________________________________________ [hidden email] 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. ______________________________________________ [hidden email] 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. |
In reply to this post by bini267
Hi Areti,
Maybe this will help: scrounging<-data.frame( behav=sample(c("inactive","active","foraging","snoozing"),50,TRUE), substr=sample(c("tree","ground","vine","air"),50,TRUE)) scrounge.tab<-table(scrounging) barplot(scrounge.tab) legend(3.8,14,c("inactive","active","foraging","snoozing"), fill=c("gray80","gray60","gray40","gray20")) Jim On Thu, Mar 11, 2021 at 9:54 AM Areti Panopoulou <[hidden email]> wrote: > > Hello, > > I am trying to make a stacked barplot with different behaviours > ("inactive", "active", "foraging" etc) on different substrates ("tree", > "ground" etc). I have found this function: > > # Stacked Bar Plot with Colors and Legend > counts <- table(mtcars$vs, mtcars$gear) > barplot(counts, main="Car Distribution by Gears and VS", > xlab="Number of Gears", col=c("darkblue","red"), > legend = rownames(counts)) > > But don't know how to apply it. Can anybody help me apply the function to > work with my variables ( I can send more information if necessary, or make > any clarifications). > > This is a great help, thanks a lot. > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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. ______________________________________________ [hidden email] 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. |
> table(scrounging)
substr behav air ground tree vine active 1 5 3 6 foraging 2 6 3 0 inactive 6 1 1 3 snoozing 2 1 3 7 > likert(t(table(scrounging))) ________________________________________ From: R-help <[hidden email]> on behalf of Jim Lemon <[hidden email]> Sent: Wednesday, March 10, 2021 19:35 To: Areti Panopoulou; r-help mailing list Subject: [External] Re: [R] Help please Hi Areti, Maybe this will help: scrounging<-data.frame( behav=sample(c("inactive","active","foraging","snoozing"),50,TRUE), substr=sample(c("tree","ground","vine","air"),50,TRUE)) scrounge.tab<-table(scrounging) barplot(scrounge.tab) legend(3.8,14,c("inactive","active","foraging","snoozing"), fill=c("gray80","gray60","gray40","gray20")) Jim On Thu, Mar 11, 2021 at 9:54 AM Areti Panopoulou <[hidden email]> wrote: > > Hello, > > I am trying to make a stacked barplot with different behaviours > ("inactive", "active", "foraging" etc) on different substrates ("tree", > "ground" etc). I have found this function: > > # Stacked Bar Plot with Colors and Legend > counts <- table(mtcars$vs, mtcars$gear) > barplot(counts, main="Car Distribution by Gears and VS", > xlab="Number of Gears", col=c("darkblue","red"), > legend = rownames(counts)) > > But don't know how to apply it. Can anybody help me apply the function to > work with my variables ( I can send more information if necessary, or make > any clarifications). > > This is a great help, thanks a lot. > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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. ______________________________________________ [hidden email] 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. ______________________________________________ [hidden email] 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. |
Dear Areti,
this dcast data.frame presents the same info as Jim's barplot reshape2::dcast(data=scrounging, formula=behav~substr, fun.aggregate=length) yielding behav air ground tree vine 1 active 5 4 3 3 2 foraging 2 1 3 4 3 inactive 0 4 4 5 4 snoozing 3 5 1 3 I tried to use likert by the example in the example in ?likert::likert library(likert) data(pisaitems) items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q'] names(items29) <- c("Magazines", "Comic books", "Fiction", "Non-fiction books", "Newspapers") l29 <- likert(items29) l29 lapply(items29, levels) like this u <- unique(scrounging$behav) levels.behav <- c("inactive", u[u!="inactive"]) scrounging$behav <- factor(x=scrounging$behav, levels=levels.behav) u <- unique(scrounging$substr) levels.substr <- c("ground", u[u!="ground"]) scrounging$substr <- factor(x=scrounging$substr, levels=levels.substr) likert::likert(scrounging) yielding Item inactive active foraging snoozing 1 behav 36 20 20 24 2 substr 20 28 30 22 but I doubt this is meaningful ... Best, Rasmus ______________________________________________ [hidden email] 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. |
The likert() function in library(likert) is not the same as
the likert() function in library(HH). The likert function in the likert package creates an object that needs to be plotted. For the likert package you left out the line plot(likert::likert(scrounging)) This plot is not consistent with what your initial email said it was looking for. Both Jim Lemon and I gave you plots that are consistent with your description. You could probably get a similar plot from likert::likert(), but not by the lines you are using. The likert::likert() function does not work with the table that HH::likert() and barplot() are using. look at str(l29) to see what it needs The likert package and the HH package cannot be loaded simultaneously. Their use the same function names in incompatible ways. How to get the ?likert::likert plot using HH: HH::likert(t(sapply(items29, table)), as.percent=TRUE, positive.order=TRUE) Here is a complete example using Jim Lemon's data. ## NO library() statements! ## The likert and HH packages have incompatible usage ## of the same function names. ## this is the example from ?likert::likert data(pisaitems, package="likert") items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q'] names(items29) <- c("Magazines", "Comic books", "Fiction", "Non-fiction books", "Newspapers") ## plot using likert package l29 <- likert::likert(items29) likert:::plot.likert(l29) ## plot using HH package HH::likert(t(sapply(items29, table)), as.percent=TRUE, positive.order=TRUE, main="HH::likert") HH::likert(t(sapply(items29, table)), as.percent=TRUE, positive.order=TRUE, main="HH::likert", auto.key=list(columns=2), scales=list(y=list(tck=c(0,2)))) ## prettier ## Jim Lemon's example scrounging <- data.frame( behav=sample(c("inactive","active","foraging","snoozing"),50,TRUE), substr=sample(c("tree","ground","vine","air"),50,TRUE)) scroungeTable <- t(table(scrounging)) scroungeTable HH::likert(scroungeTable) ## I don't think Jim Lemon's example can be used directly in the likert package. ## look at str(l29) ## and notice that it must include both raw data and the table l29$results head(l29$items) ## For any further discussion on this list please include the output from dput(head(yourRealData)) ## in the body of the email. ## Jim's example is based on base graphics barplot ## The HH likert() function is based on lattice barchart. ## the likert package's likert:::plot.likert() function is based on ggplot. ________________________________________ From: R-help <[hidden email]> on behalf of Rasmus Liland <[hidden email]> Sent: Thursday, March 11, 2021 09:03 To: Areti Panopoulou Cc: r-help Subject: [External] Re: [R] [External] Re: Help please Dear Areti, this dcast data.frame presents the same info as Jim's barplot reshape2::dcast(data=scrounging, formula=behav~substr, fun.aggregate=length) yielding behav air ground tree vine 1 active 5 4 3 3 2 foraging 2 1 3 4 3 inactive 0 4 4 5 4 snoozing 3 5 1 3 I tried to use likert by the example in the example in ?likert::likert library(likert) data(pisaitems) items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q'] names(items29) <- c("Magazines", "Comic books", "Fiction", "Non-fiction books", "Newspapers") l29 <- likert(items29) l29 lapply(items29, levels) like this u <- unique(scrounging$behav) levels.behav <- c("inactive", u[u!="inactive"]) scrounging$behav <- factor(x=scrounging$behav, levels=levels.behav) u <- unique(scrounging$substr) levels.substr <- c("ground", u[u!="ground"]) scrounging$substr <- factor(x=scrounging$substr, levels=levels.substr) likert::likert(scrounging) yielding Item inactive active foraging snoozing 1 behav 36 20 20 24 2 substr 20 28 30 22 but I doubt this is meaningful ... Best, Rasmus ______________________________________________ [hidden email] 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. |
That is such a nice email crammed with
useful info I'm sure Areti Panopoulou appreciates. JR ______________________________________________ [hidden email] 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. |
Thank you so much everyone for your time and help! I really appreciate it.
Kind Regards, Areti On Thu, Mar 11, 2021 at 10:34 PM Rasmus Liland <[hidden email]> wrote: > That is such a nice email crammed with > useful info I'm sure Areti Panopoulou > appreciates. JR > [[alternative HTML version deleted]] ______________________________________________ [hidden email] 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. |
Free forum by Nabble | Edit this page |