-1

Here i need to make a chart using R-Script and i am using a Data frame called DF.

a<-c("01-01-2013 12:00:00 AM","01-02-2013 12:00:00 AM",
     "01-03-2013 12:00:00 AM","01-04-2013 12:00:00 AM",
     "01-05-2013 12:00:00 AM")
b<-c(1,2,3,4,5)
c<-c(11,12,13,14,15)
d<-c(101,102,103,104,105)
e<-c(50,55,34,30,45)
DF<-data.frame(DATETIME=a,DWATT=b,TNH=c,CSGV=d,CIV=e)

Requirement is, need a bar-chart using R-SCRIPT to indicate the counting for a particular DATETIME for all the four tags (DWATT,TNH,CSGV,CIV). And it should repeat for each DATETIME.

Here, x-axis should come as DATETIME and Y-axis should be for count. Chart should show the counting of each tags (DWATT,TNH,CSGV,CIV) for each timing.

Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
  • 2
    Congratulations on providing reproducible data in your first Stack Overflow question - most people don't get that far. Please show us the bar chart code that you have written so far. Just in case (as a beginner) you are unclear, Stack Overflow is a place where we help you fix programming problems when you get stuck. It is not a place where other people will simply write all the code for you. Thanks. – SlowLearner Sep 08 '13 at 22:06

2 Answers2

1

You can start with this:

barplot(t(as.matrix(DF[,2:5])), beside=F, names.arg=as.Date(DF[,1], "%d-%m-%Y"))

or this:

barplot(t(as.matrix(DF[,2:5])), beside=T, names.arg=as.Date(DF[,1], "%d-%m-%Y"))
zero323
  • 322,348
  • 103
  • 959
  • 935
  • Hi Could you please tell me one more thing that how can we save this plot as PDF format ? – user2759674 Sep 09 '13 at 05:45
  • http://stackoverflow.com/search?q=R+save+plot+to+pdf or https://encrypted.google.com/search?&q=R+save+plot+to+pdf – zero323 Sep 09 '13 at 10:21
  • Hi, But here i not getting exact timing. It only shows current date and not with timing. I tried to change format ["%m/%d/%Y %I:%M:%S %p"]. But i not getting anything that time. Is there have any other special format for date ? – user2759674 Sep 11 '13 at 09:00
  • Your date is separated by hyphens not slashes. "%d-%m-%Y %I:%M:%S %p" – zero323 Sep 11 '13 at 09:13
  • I tried with hyphens also then also not coming time along with date. – user2759674 Sep 12 '13 at 09:08
  • You can always convert your string s to POSIX dates/time using strptime(a, "%d-%m-%Y %I:%M:%S %p") and then format them as you wish using strftime – zero323 Sep 12 '13 at 10:45
0
install.packages("plotly")
library(plotly)
plot_ly(data = DF,x  = as.Date(DF$DATETIME,"%d-%m-%Y"),y = ~DWATT,type = "bar",name = "DWatt")%>%
add_trace(data = DF,x  = as.Date(DF$DATETIME,"%d-%m-%Y"),y = ~TNH,type = "bar",name = "TNH")%>%
 add_trace(data = DF,x  = as.Date(DF$DATETIME,"%d-%m-%Y"),y = ~CSGV,type = "bar",name = "CSGV")%>%
add_trace(data = DF,x  = as.Date(DF$DATETIME,"%d-%m-%Y"),y = ~CIV,type = "bar",name = "CIV")

use this if you want interactive :)