Skip to content

Instantly share code, notes, and snippets.

@asimjalis
Last active August 29, 2015 14:19
Show Gist options
  • Save asimjalis/469f82f6e4c13be822b7 to your computer and use it in GitHub Desktop.
Save asimjalis/469f82f6e4c13be822b7 to your computer and use it in GitHub Desktop.
R bar plots for time series of HBase region server writes

Region Server Writes

Uses R to create bar plots of region server writes.

Steps

  1. Save the sample data into ~/tmp/region-data.csv

  2. Install R and start R console

  3. Paste the R commands into R console

Chart

Bar Plot

Time Region Total Writes New Writes
1 Start 15 15
1 C 16 16
1 F 18 18
1 J 15 15
1 N 10 10
1 R 9 9
1 T 9 9
1 W 5 5
2 Start 73 58
2 C 74 58
2 F 87 69
2 J 90 75
2 N 45 35
2 R 56 47
2 T 36 27
2 W 24 19
3 Start 175 102
3 C 176 102
3 F 198 111
3 J 191 101
3 N 116 71
3 R 181 125
3 T 97 61
3 W 49 25
# Paste this into R console.
# Install packages once
install.packages(c("reshape2","magrittr","ggplot2"), repos="http://cran.r-project.org" )
# Import symbols
library(reshape2)
library(magrittr)
library(ggplot2)
# Define input source
csvfile <- '~/tmp/region-data.csv'
# Graph data
csvfile %>% read.csv %>% # Read CSV
subset(.,select=-c(New.Writes)) %>% # Drop New Writes column
dcast(.,Time~Region,value.var='Total.Writes') %>% # Long to wide
melt(.,id.vars=c('Time')) %>% # Wide to long
ggplot(., aes(x=Time, y=value,fill=variable)) + # Plot
geom_bar(stat='identity') +
scale_fill_discrete(name="Regions") +
xlab('Time') +
ylab('Total Writes')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment