2016-11-25 69 views
0

我創建了一個條形圖,其中包含多個因子,我通過特定的時間公式收集了多個數據點。現在我想要在條形圖中隨時間顯示這些數據。因此我定義了以下命令並獲得了下圖。這裏是數據。圖表內排序日期

Zeitpunkt 20.05.2016 27.05.2016 03.06.2016 10.06.2016 17.06.2016 24.06.2016 01.07.2016 08.07.2016 15.07.2016 22.07.2016 28.07.2016 
Innoplattform 1,725806452 2,633333333 3,689655172 2,2 2,846153846 2,571428571 2,884615385 2,131578947 1,954545455 2,956521739 2 
WhatsApp 5,548387097 5,533333333 5,775862069 5,96 6,288461538 4,69047619 5,076923077 5,394736842 5,204545455 6,347826087 5,909090909 
Skype 0,483870968 1,133333333 1,310344828 1,1 1,346153846 0,261904762 0,480769231 0,526315789 0,545454545 1,369565217 0,659090909 
Adobe Connect 0 0,083333333 0 0 0 0 0 0,052631579 0,272727273 0,086956522 0 
Facebook 0 0 0,189655172 0,04 0 0 0 0 0 0 0 
Telefon 1,064516129 0,983333333 0,706896552 0,6 1,519230769 0,166666667 0,115384615 0,368421053 0,409090909 0,347826087 0,227272727 
E-Mail 0 1,166666667 1 0,7 1,711538462 0,452380952 0,942307692 0,236842105 1,022727273 2,413043478 2,090909091 

的數據也超過爲.csv文件中提供的鏈接:

https://www.dropbox.com/s/o3jgwk76lx3v0i5/Verwendete%20Tools2.csv?dl=0

基於這些DATAS我所定義的DATAS爲數據幀創建barplot。因此是以下命令。

Tools <- read.csv(file="Verwendete Tools2.csv", header = TRUE, sep = ";", dec=",") 

attach(Tools)  # Datensatz Tools laden  

df <- data.frame(X01.07.2016, X03.06.2016, X08.07.2016, X10.06.2016, X15.07.2016, X17.06.2016, X20.05.2016, X22.07.2016, X24.06.2016, X27.05.2016, X28.07.2016) 

barplot(as.matrix(df), main="Relative Häufigkeit der für die virtuelle Kommunikation genutzten Tools", ylab = "Relative Häufigkeit", xlab="Zeitpunkte der Umfragen", cex.lab = 1.5, cex.main = 1.4, beside=TRUE, col=c(1, 2, 3, 4, 5, 6, 7)) 

enter image description here

現在有什麼錯呢?通常這正是我想要得到的圖表。但問題是,x軸上的日期不是按日期排序的。 R只是將日期標識爲正常數字而不是日期..但是當我將這些數據點轉換爲日期時,我也將其他數據點轉換爲日期,我不想要的日期。

有人可以幫助我,我怎麼可以在圖中排序這些日期?或者有另一種解決方案,我可以如何創建此圖表?

非常感謝!

+0

執行代碼產量'錯誤:對象 'X01.07.2016' 不found'。請閱讀[如何在R中提供最小重現性示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610)。然後相應地編輯並改進您的帖子。好的帖子通常提供最少的輸入數據,所需的輸出數據和代碼嘗試 - 在新的/乾淨的R會話中進行全部複製 - 粘貼 - 運行。 – lukeA

+0

我編輯了問題,並提供了保存在Dropbox上的數據集作爲csv文件。我不明白你爲什麼會得到這個錯誤。我在R的指揮官那裏試了一下,它完美地生成了條形圖..但是我無法在x軸上以正確的順序得到它。 –

+0

您正在'矩陣'上使用'barplot'。您的x軸由列名決定。列名是字符串(它們必須是字符串)。它們按照你的'data.frame()'調用中的列硬編碼的順序排列。如果您想以不同的順序輸入它們,請按不同的順序輸入它們。如果你想讓它們以不同的方式顯示,請使用'barplot'的'names.arg'參數指定你想要的字符串作爲標籤。 – Gregor

回答

0

你可以做

download.file("https://www.dropbox.com/s/o3jgwk76lx3v0i5/Verwendete%20Tools2.csv?dl=1", 
       tf <- tempfile(fileext = ".csv"), mode="wb") 
Tools <- read.csv(file=tf, header = TRUE, sep = ";", dec=",", check.names = F) 
m <- as.matrix(Tools[-1]) 
barplot(m, beside=TRUE, col=seq_len(nrow(m))) 

列已經排序在數據幀Tools

假設會不會是這樣

m <- m[,sample(seq_along(colnames(m)))] # shuffle columns 
barplot(m, beside=TRUE, col=seq_len(nrow(m))) 

你仍然可以做

m <- m[, order(as.Date(colnames(m), "%d.%m.%Y"))] # order by date 
barplot(m, beside=TRUE, col=seq_len(nrow(m))) 
+0

非常感謝!有用! –