Talvien Talvien - 1 year ago 121
R Question

No bars shown in R ggplot Gantt chart

I have the following dataset as source:

structure(list(JobName = structure(c(1L, 1L, 1L, 2L, 2L, 2L), .Label = ("ATLAS_Admin_DeployClientDatabase", "ATLAS_Admin_ParseMasterCubeDatabase", ATLAS_Admin_xBackup_DeleteOldTable", "BDC_DatabaseMaintenanceJob_ALL_DATABASES", collection_set_1_noncached_collect_and_upload", "CoreX_SAP_B23_dreprecated", CoreXBI_ETL_1014_01Stage", "CoreXBI_ETL_1014_02DWH_Cube", "CoreXBI_ETL_1114_02DWH_Cube", "CoreXBI_ETL_1294_B23", CoreXBI_ETL_AutoTest", "Cycle_Log", "Delphi DEV Load", "Delphi DEV Monthly", mdw_purge_data_[Z_MAS_MDW]", "QA_CoreXBI_ETL_1010", "QA_CoreXBI_ETL_1294", Shrink_the_Logs", "SSIS Server Maintenance Job", "syspolicy_purge_history", sysutility_get_cache_tables_data_into_aggregate_tables_daily", "sysutility_get_cache_tables_data_into_aggregate_tables_hourly", "sysutility_get_views_data_into_cache_tables", "Z_MAS_ADMIN_ALRS", "Z_MAS_ADMIN_Backup_AMOTables", "Z_MAS_ADMIN_Check_Cube_Space", "Z_MAS_ADMIN_Check_Disk_Space", "Z_MAS_ADMIN_Extract_Job_History", "Z_MAS_ADMIN_Monitoring", "Z_MAS_MaintenancePlan.weekly_bak_clean", "Z_MICE_System_Database_Backup_weekly"), class = "factor"), RunDateTime = tructure(c(1478788776, 1479292645, 1479307979, 1479292220, 1479307916, 479314398), class = c("POSIXct", "POSIXt"), tzone = ""), StartWeekday = tructure(c(5L, 7L, 7L, 7L, 7L, 7L), .Label = c("Friday", "Monday", Saturday", "Sunday", "Thursday", "Tuesday", "Wednesday"), class = "factor"), tartTime = structure(c(-2209108824, -2209123355, -2209108021, -2209123780, 2209108084, -2209101602), class = c("POSIXct", "POSIXt"), tzone = ""), ndRunDateTime = structure(c(1478790159, 1479294190, 1479309546, 1479292284, 479307977, 1479314459), class = c("POSIXct", "POSIXt"), tzone = ""), ndWeekday = structure(c(5L, 7L, 7L, 7L, 7L, 7L), .Label = c("Friday", Monday", "Saturday", "Sunday", "Thursday", "Tuesday", "Wednesday"), class = factor"), EndTime = structure(c(-2209107441, -2209121810, -2209106454, 2209123716, -2209108023, -2209101541), class = c("POSIXct", "POSIXt"), tzone "")), .Names = c("JobName", "RunDateTime", "StartWeekday", StartTime", "EndRunDateTime", "EndWeekday", "EndTime"), row.names = c(NA, L), class = "data.frame")

Now I use the following script to create a Gantt chart out of data that should show me the durations of the different jobs in the timeline.

vars <- c("RunDateTime", "EndRunDateTime", "StartTime", "EndTime")
dataset[vars] <- lapply(dataset[vars], as.POSIXct, format = "%Y-%m-%dT%H:%M:%S")
df <- with(dataset, data.frame(name = JobName, start = RunDateTime, end = EndRunDateTime))
mdfr <- melt(df, measure.vars = c("start", "end"))

ggplot(mdfr, aes( x = value, y = name, color = variable))
geom_line(size = 6)

My problem is, that I get a chart with JobNames on the y-axis and DateTimes on the x-axis, but no values or bars in it.

enter image description here

Any idea what it's about?

EDIT: Next problem is now, that it connects the very first start time with the very last end time...

Answer Source

You're not adding the geoms to the plot. Try:

ggplot(mdfr, aes( x = value, y = name, color = variable)) +
    geom_line(size = 6) +
    xlab(NULL) +
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download