Forum Discussion

mars00's avatar
mars00
Regular Visitor
4 years ago
Solved

Custom visual R assistance with as.POSIXct

Hi, I'm a total novice with R and I'm trying to get the below to work, however it seems I'm using the as.POSIXCT incorrect in order to get this line: " work scale_x_datetime(breaks = date_breaks("2 ...
  • mars00's avatar
    mars00
    4 years ago

    But i can't seem to get the code to work when creating a custom visual, i fixed some pieces which i still did wrong, but it states it is unable to find the function while the logic does work in the R script editor.

    source('./r_files/flatten_HTML.r')

    ############### Library Declarations ###############
    libraryRequireInstall("ggplot2");
    libraryRequireInstall("plotly")
    libraryRequireInstall("htmlwidgets")
    ####################################################

    ################### Actual code ####################
    dataset <- Values

    dataset$`Start Time` <- as.POSIXct(dataset$`Time_Move`,format="%Y-%m-%dT%H:%M:%OS", tz ="GMT")
    dataset$`end_move`<- as.POSIXct(dataset$`end_move`,format="%Y-%m-%dT%H:%M:%OS", tz="GMT")

    g =ggplot(Values ,aes(x=dataset$`Start Time`, y=dataset$`CHEID`, color= dataset$`HNDTYP`)) +
    geom_segment(aes(x=dataset$`Start Time`,xend=dataset$`End Time` ,yend=dataset$`CHEID`),size=15) +
    scale_colour_discrete(guide=guide_legend(override.aes=list(size=10))) +
    scale_x_datetime(breaks = date_breaks("1 hour"), labels=date_format("%m-%d %Hh"))+
    theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 1)) +


    ggtitle("Rescue by Time_Move and end_move") + xlab("Time") + ylab("Crane") + theme_bw();
    ####################################################

    ############# Create and save widget ###############
    p = ggplotly(g);
    internalSaveWidget(p, 'out.html');
    ####################################################

    ################ Reduce paddings ###################
    ReadFullFileReplaceString('out.html', 'out.html', ',"padding":[0-9]*,', ',"padding":0,')
    ####################################################