[R] [External] Re: [External] Re: Help please

Richard M. Heiberger rmh @end|ng |rom temp|e@edu
Thu Mar 11 19:48:46 CET 2021

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
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)

## 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",
           scales=list(y=list(tck=c(0,2)))) ## prettier

## Jim Lemon's example
scrounging <- data.frame(

scroungeTable <- t(table(scrounging))

## I don't think Jim Lemon's example can be used directly in the likert package.
## look at
## and notice that it must include both raw data and the table

## For any further discussion on this list please include the output from
## 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 using r-project.org> on behalf of Rasmus Liland <jral using posteo.no>
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)


             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

        items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
        names(items29) <- c("Magazines", "Comic books", "Fiction",
                           "Non-fiction books", "Newspapers")
        l29 <- likert(items29)
        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)


            Item inactive active foraging snoozing
        1  behav       36     20       20       24
        2 substr       20     28       30       22

but I doubt this is meaningful ...


More information about the R-help mailing list