我对R是新手,我看过几个网站,关于如何在R中制作一个Likert堆叠条形图(以及这个网站上的一个问题)。我一个也不懂。每个例子都有无数的命令。就好像他们在向我展示如何通过包含他们所能想到的所有可能的属性来画图,而我想要的只是一个答案:图(x,y)
为了简单起见,让我们假设我的数据有两个问题,一个3pt的Likert标度(A、B和C),排列在一个CSV中,如下所示:
A B C
Q1 25 31 56
Q2 73 19 4这些数字代表了用这个答案回答问题的人数。例如,对于问题2,19人选择了Likert答复B。
什么是最短数量的命令,可以创建一个堆叠条形图?
发布于 2017-04-04 01:40:35
这应该给你一个步骤的想法:
Question <- c("Q1", "Q2")
A <- c(25,73)
B <- c(31,19)
C <- c(56,4)
data <- data.frame(Question, A, B, C)
# Install the "reshape" package
install.packages("reshape")
# Load reshape package into working directory
library(reshape)
# Melt data to long format
data.melt <- melt(data, id = ("Question"), measure.vars = c("A", "B", "C"))
# Install ggplot2 package
install.packages("ggplot2")
# Load ggplot2 package into working directory
library(ggplot2)
# Create your figure
ggplot(data.melt, aes(x = Question, y = value, fill = variable)) +
geom_bar(stat = "identity")https://stackoverflow.com/questions/43196827
复制相似问题