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.
Help please
10 messages · Rui Barradas, Jim Lemon, Richard M. Heiberger +2 more
install.packages("HH")
library(HH)
?likert
From your description, I think your data is set up to work with likert()
From: R-help <r-help-bounces at r-project.org> on behalf of Areti Panopoulou <aretipanopoulou at gmail.com>
Sent: Wednesday, March 10, 2021 13:29
To: r-help at r-project.org
Subject: [External] [R] Help please
Sent: Wednesday, March 10, 2021 13:29
To: r-help at r-project.org
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]]
______________________________________________
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.
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]]
______________________________________________ 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.
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 <r-help-bounces at r-project.org> on behalf of Richard M. Heiberger <rmh at temple.edu>
Sent: Wednesday, March 10, 2021 17:58
To: Areti Panopoulou; r-help at r-project.org
Subject: Re: [R] [External] Help please
Sent: Wednesday, March 10, 2021 17:58
To: Areti Panopoulou; r-help at r-project.org
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 <r-help-bounces at r-project.org> on behalf of Areti Panopoulou <aretipanopoulou at gmail.com>
Sent: Wednesday, March 10, 2021 13:29
To: r-help at r-project.org
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]]
______________________________________________
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.
______________________________________________
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.
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
<aretipanopoulou at gmail.com> 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]]
______________________________________________ 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.
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 <r-help-bounces at r-project.org> on behalf of Jim Lemon <drjimlemon at gmail.com>
Sent: Wednesday, March 10, 2021 19:35
To: Areti Panopoulou; r-help mailing list
Subject: [External] Re: [R] Help please
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
<aretipanopoulou at gmail.com> 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]]
>
> ______________________________________________
> 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.
______________________________________________
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.
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20210311/5e5a412e/attachment.sig>
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 <r-help-bounces at r-project.org> on behalf of Rasmus Liland <jral at posteo.no>
Sent: Thursday, March 11, 2021 09:03
To: Areti Panopoulou
Cc: r-help
Subject: [External] Re: [R] [External] Re: Help please
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
That is such a nice email crammed with useful info I'm sure Areti Panopoulou appreciates. JR -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20210311/5f964368/attachment.sig>
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 <jral at posteo.no> wrote:
That is such a nice email crammed with useful info I'm sure Areti Panopoulou appreciates. JR