Bar Chart Using R-Script

418 views Asked by At

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.

2

There are 2 answers

6
zero323 On BEST ANSWER

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"))
0
Uttam Gogineni On
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 :)