第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

R中的堆積條形圖

R中的堆積條形圖

吃雞游戲 2019-12-04 10:00:23
我已經(jīng)看過關(guān)于R中堆積條形圖的類似問題,但是我仍然沒有運(yùn)氣。我創(chuàng)建了以下數(shù)據(jù)框:        A   B   C   D   E   F    G     1 480 780 431 295 670 360  190     2 720 350 377 255 340 615  345     3 460 480 179 560  60 735 1260     4 220 240 876 789 820 100   75A:G代表x軸,y軸為持續(xù)時間(秒)。我將如何在R中堆疊以下數(shù)據(jù)?非常感謝您的時間和幫助。
查看完整描述

3 回答

?
慕仙森

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個贊

數(shù)據(jù)集:


dat <- read.table(text = "A   B   C   D   E   F    G

1 480 780 431 295 670 360  190

2 720 350 377 255 340 615  345

3 460 480 179 560  60 735 1260

4 220 240 876 789 820 100   75", header = TRUE)

現(xiàn)在,您可以將數(shù)據(jù)框轉(zhuǎn)換為矩陣并使用該barplot函數(shù)。


barplot(as.matrix(dat))


查看完整回答
反對 回復(fù) 2019-12-04
?
紫衣仙女

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個贊

使用ggplot2的方法有些不同:


dat <- read.table(text = "A   B   C   D   E   F    G

1 480 780 431 295 670 360  190

2 720 350 377 255 340 615  345

3 460 480 179 560  60 735 1260

4 220 240 876 789 820 100   75", header = TRUE)


library(reshape2)


dat$row <- seq_len(nrow(dat))

dat2 <- melt(dat, id.vars = "row")


library(ggplot2)


ggplot(dat2, aes(x = variable, y = value, fill = row)) + 

  geom_bar(stat = "identity") +

  xlab("\nType") +

  ylab("Time\n") +

  guides(fill = FALSE) +

  theme_bw()

這給出了:


如果要包含圖例,請刪除該guides(fill = FALSE)行。


查看完整回答
反對 回復(fù) 2019-12-04
?
炎炎設(shè)計(jì)

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個贊

我顯然不是一個很好的R編碼器,但是如果您想用ggplot2做到這一點(diǎn):


data<- rbind(c(480, 780, 431, 295, 670, 360,  190),

             c(720, 350, 377, 255, 340, 615,  345),

             c(460, 480, 179, 560,  60, 735, 1260),

             c(220, 240, 876, 789, 820, 100,   75))


a <- cbind(data[, 1], 1, c(1:4))

b <- cbind(data[, 2], 2, c(1:4))

c <- cbind(data[, 3], 3, c(1:4))

d <- cbind(data[, 4], 4, c(1:4))

e <- cbind(data[, 5], 5, c(1:4))

f <- cbind(data[, 6], 6, c(1:4))

g <- cbind(data[, 7], 7, c(1:4))


data           <- as.data.frame(rbind(a, b, c, d, e, f, g))

colnames(data) <-c("Time", "Type", "Group")

data$Type      <- factor(data$Type, labels = c("A", "B", "C", "D", "E", "F", "G"))


library(ggplot2)


ggplot(data = data, aes(x = Type, y = Time, fill = Group)) + 

       geom_bar(stat = "identity") +

       opts(legend.position = "none")


查看完整回答
反對 回復(fù) 2019-12-04
  • 3 回答
  • 0 關(guān)注
  • 898 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號