ggplot arrangeGrob scale colour and size

225 views Asked by At

I am looking for simple idea how to make the same colour and size scale for all devices. Maybe there is a simple way how to change this code but I am lost :)

Please, be so kind and help me find answer:)

I attached: input dataset , code and ggplot output png file

Best regards Robert

require(reshape2)
require(data.table)

DEV <- fread(input = "http://bigosr.com/wp-content/uploads/2014/07/DEV.csv")
DEV[,PRF_TIMESTAMP:=as.POSIXct(PRF_TIMESTAMP)]
plot_list <- lapply(unique(DEV$DEV_ID), 
                    function(x) {
                      watermark_x <- as.POSIXct(max(DEV[DEV_ID==x,]$PRF_TIMESTAMP) + difftime( min(DEV[DEV_ID==x,]$PRF_TIMESTAMP), max(DEV[DEV_ID==x,]$PRF_TIMESTAMP) ,units = "days")/2)
                      watermark_y <- max(DEV[DEV_ID==x,]$TOT_IO)/2
                      watememark_dev_name    <- volums[DEV_ID==x,unique(DEV_ID)] 

                      g.top <- ggplot(DEV[DEV_ID==x,]) +
                        #geom_jitter()  +
                        theme_bw() +
                        scale_color_continuous(low="green",high="red",guide=FALSE)+
                        theme(plot.margin = unit(c(1,5,-30,6),units="points"),axis.title.y = element_text(vjust =0.25)) +
                        labs(y = "Utilization (%)", x= "Time") +
                        geom_line(aes(x = PRF_TIMESTAMP, y = UTY, colour=RT)) +
                        scale_x_datetime(  breaks=("2 hour") ,labels=date_format("%H"))

                      g.top_cache <- ggplot(DEV[DEV_ID==x,]) +
                        #geom_jitter()  +
                        theme_bw() +
                        scale_color_continuous(low="green",high="red",guide=FALSE)+
                        theme(plot.margin = unit(c(1,5,-30,6),units="points"),axis.title.y = element_text(vjust =0.25)) +
                        labs(y = "Cache (%)", x= "Time") +
                        geom_line(aes(x = PRF_TIMESTAMP , y=TOTAL_CACHE_HIT_PERC_OVERALL))+
                        scale_x_datetime(  breaks=("2 hour") ,labels=date_format("%H"))

                      g.bottom <- ggplot(DEV[DEV_ID==x,], aes(x = PRF_TIMESTAMP, y = TOT_IO, size=SIZE/1000 ,colour=RT)) +
                        geom_jitter() +
                        theme_bw() +
                        scale_color_continuous(low="green",high="red")+
                        theme(legend.position="bottom") +
                        theme(plot.margin = unit(c(0,5,1,1),units="points")) +
                        labs(y = "IOPS", x= "Time",colour="Response time \n(ms)",size = "Transfer size \nGB")  +
                        ggplot2::annotate("text", x = watermark_x, y = watermark_y , label = as.character(watememark_dev_name) ,
                                          hjust=0.5, vjust=0.5, col="black", cex=18,
                                          fontface = "bold", alpha = 0.4) +
                        scale_x_datetime(  breaks=("2 hour"),  labels=date_format("%H"))

                      arrangeGrob(g.top,g.top_cache,g.bottom, heights = c(1/5,1/5,3/5))
                    })


png(filename = "./totalIO.png",width = length(plot_list) * 500/2, height = length(plot_list) * 500)
do.call(grid.arrange,   c( plot_list ,nrow = length(plot_list))) 
dev.off()

totalIO.png

0

There are 0 answers