Skylar

A intelligent software assistant written in Java

logo

Projekt HTML Handbuch PDF Handbuch

     

Analyse mit R

RNeo4j - analyse

# https://github.com/nicolewhite/RNeo4j
library(RNeo4j)

# connect to database
graph = startGraph("http://skylar.livingfire.de/db/data/", username="skylar", password="skylar")


# define query
query <- "
MATCH (n:Listdata)
WHERE n.group = 'running' AND n.dimension = 'distance'
RETURN n
"

# retrieve nodes as List
nodes <- cypherToList(graph, query)

# retrieve vector of values
values <- sapply(nodes, function(node) node$n$value)

Plotten mit visNetwork - analyse

Read article: Use visNetwork to visualize your Neo4j Schema

Plotten mit Plotly - analyse

# https://github.com/nicolewhite/RNeo4j
library(RNeo4j)

# connect to database
graph = startGraph("http://skylar.livingfire.de/db/data/", username="skylar", password="skylar")


# define query
query <- "
MATCH (n:Listdata)
WHERE n.group = 'running'
AND n.dimension IN ['speed','distance','timeTotal']
RETURN  n
"

# retrieve nodes as List
nodes <- cypherToList(graph, query)

# setup plotData
plotData <- data.frame()
for(node in nodes) {
  plotData[node$n$logstash, node$n$dimension] <- node$n$value
}
plotData <- cbind(dateTime = rownames(plotData), plotData)

# convert to R data types
plotData$dateTime <- as.POSIXct(plotData$dateTime, "%Y-%m-%dT%H:%M:%S", tz="UTC")
plotData$distance <- as.numeric(plotData$distance)
plotData$timeTotal <- as.numeric(plotData$timeTotal)
plotData$speed <- as.numeric(plotData$speed)


# https://plot.ly/r/getting-started/
library(plotly)

axisX <- list(
  title="time"
)

axisY <- list(
  tickfont = list(color = "#4885ed"),
  title = "speed",
  titlefont = list(color = "#4885ed")
)

axisY2 <- list(
  tickfont = list(color = "#ff7f0e"),
  title = "distance",
  titlefont = list(color = "#ff7f0e"),
  position = 0.10,
  anchor = "free",
  overlaying = "y",
  side = "left"
)

axisY3 <- list(
  tickfont = list(color = "#3cba54"),
  title = "totalTime",
  titlefont = list(color = "#3cba54"),
  position = 0.20,
  anchor = "free",
  overlaying = "y",
  side = "left"
)

# create plot
p <- plot_ly(plotData, x = ~dateTime) %>%
  add_lines(y = ~speed, name = "speed", line = list(shape = "linear")) %>%
  add_lines(y = ~distance, yaxis = "y2", name = "distance", line = list(shape = "linear")) %>%
  add_lines(y = ~timeTotal, yaxis = "y3", name = "timeTotal", line = list(shape = "linear"))  %>%
  layout(
    title = "Jogging",
    yaxis = axisY,
    yaxis2 = axisY2,
    yaxis3 = axisY3,
    xaxis = axisX
  )

# show plot
p

# save plot
htmlwidgets::saveWidget(as_widget(p), "/tmp/graph.html")