Need help with for cycle!

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Need help with for cycle!

This post was updated on .
Hey guys,
it`s my 2nd day with R and I`m just starting to make something. Could you help me a bit? I`d be very grateful. The thing is that I`m using, but it can`t make different line width, when using add_segments. I thought that maybe I could write a for cycle for creating those lines between points one-by-one instead of drawing them at once. But still don`t know how for cycle works with external sources.
My code is:
if (!"plotly" %in% installed.packages()) install.packages("plotly")
if (!"dplyr" %in% installed.packages()) install.packages("dplyr")
miestai <- read.csv("****/cities.csv")
keliones <- read.csv("****/travel.csv")
keliones$id <- seq_len(nrow(keliones))
geo <- list(
  scope = 'europe',
  lonaxis = list(range = c(20, 27)),
  lataxis = list(range = c(52.5, 56.5)),
  projection = list(type = 'choropleth'),
  showland = TRUE,
  resolution = 50,
  landcolor = toRGB("gray95"),
  countrycolor = toRGB("gray80")

p <- plot_geo(locationmode = 'Lithuania', color = I("red")) %>%
data = miestai, x = ~Lon, y = ~Lat, mode = text, text = ~miestas, textposition = 'middle right',
        textfont = list(color = '#000000', size = 14)
    ) %>%
    data = group_by(keliones, id),
    x = ~start_lon, xend = ~end_lon,
    y = ~start_lat, yend = ~end_lat,
    alpha = 0.3, size = I(7), hoverinfo = "none"
  ) %>%
    title = 'Pavadinimas',
    geo = geo, showlegend = FALSE, height=800

Files I`m using:

In travel.csv there are start and end coordinates, I need lines between them with a width of column "lin" for all rows.
Could anybody help with a code?
Thanks in advance!