0

I created a barchart with multiple Factors of datapoints i collected over a specific timehoizont. Now I wanted to illustrate these datas in a barchart over time. Therefore I defined the following commands and got the following graph. Here are the datas.

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

The data are also over the link available as .csv file:

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

Based on these datas I defined the datas as dataframe to create a barplot. Therefore are the following commands.

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

Now what's wrong with this? Normally that's exactly the graph I want to get. But the problem is, the dates on the x-axis are not sorted by dates. R just identifies the dates as normal number not as date.. but when I convert these datapoints to dates, then I also convert the other datapoints to dates, what I doesn't want to.

Can somebody help me, how I can sort these dates inside the graph? Or has somebody another solution how I can create this graph?

Thanks a lot!

  • Executing your code yields `Error: object 'X01.07.2016' not found`. Please read [how to provide minimal reproducible examples in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). Then edit & improve your post accordingly. A good post usually provides minimal input data, the desired output data & code tries - all copy-paste-run'able in a new/clean R session. – lukeA Nov 25 '16 at 16:58
  • I edited the Question and provided the dataset over dropbox as csv file. I don't understand why you get this error. I tried it in my R commander and it works perfectly to generate the barchart.. but I can't get it in the right order on the x-axis.. – G. Benesch Nov 25 '16 at 19:05
  • You are using `barplot` on a `matrix`. Your x-axis is determined by the column names. Column names are strings (they must be strings). They are in the exact order that you hard-code them as the columns in your `data.frame()` call. If you want them in a different order, type them in a different order. If you want them displayed differently, use the `names.arg` argument of `barplot` to specify the strings you want as the labels. – Gregor Thomas Nov 25 '16 at 20:22

1 Answers1

0

You can do

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

The columns are already sorted in your data frame Tools.

Assuming that would not be the case

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

you could still do

m <- m[, order(as.Date(colnames(m), "%d.%m.%Y"))] # order by date
barplot(m, beside=TRUE, col=seq_len(nrow(m)))
lukeA
  • 53,097
  • 5
  • 97
  • 100