Changing apparence of nodes in markerCLusterOptions using leaflet - r
I would like to change the default behaviour of markerClusterOptions and I add a node to each one of the end of the lines when you click on clusters:
Also, I want each node to be of the color specified by the legend.
Any way to accomplish this?
This is my code:
data %>%
leaflet() %>%
addTiles() %>%
addMarkers(
clusterOptions = markerClusterOptions()) %>%
addLegend("topright",
pal = pal, values = ~ACTIVIDAD,
title = "Number of reservations first week of 2021",
opacity = 0.8)
dput of data:
structure(list(X1 = c(21789, 17031, 6566, 5844, 19533, 5111,
15152, 12890, 22602, 22109, 21538, 13036, 2461, 7280, 12313,
2621, 13520, 6361, 4114, 11304), FHSTART = structure(c(1609867892,
1609849545, 1609765036, 1609762965, 1609857397, 1609761127, 1609844798,
1609839427, 1609874643, 1609870091, 1609866388, 1609839798, 1609754738,
1609767241, 1609837948, 1609755121, 1609840885, 1609764463, 1609758662,
1609834336), tzone = "UTC", class = c("POSIXct", "POSIXt")),
FHSTARTREAL = structure(c(1609867892, 1609849545, 1609765036,
1609762965, 1609857397, 1609761127, 1609844798, 1609839427,
1609874643, 1609870091, 1609866388, 1609839798, 1609754738,
1609767241, 1609837948, 1609755121, 1609840885, 1609764463,
1609758662, 1609834336), tzone = "UTC", class = c("POSIXct",
"POSIXt")), FHSTOPREAL = structure(c(1609870836, 1609851345,
1609771973, 1609766832, 1609858252, 1609763401, 1609846598,
1609842422, 1609944134, 1609872502, 1609868749, 1609843424,
1609758052, 1609769041, 1609838735, 1609756908, 1609843469,
1609766718, 1609759589, 1609836505), tzone = "UTC", class = c("POSIXct",
"POSIXt")), MATRICULA = c("/gg{f+>", "xg(|+)f", "/(//;af",
"e\\|{:c#", "/|\\x>)k", "\\((/;c;", "/e\\|++>", "e*(*:k~",
"\\*e/:$_", "g|*{;~}", "={(/&[;", "ee=g+^;", "\\/xx;#>",
"{//{)a:", "e*{=&+#", "xx/(;$a", "\\(*x>&#", "e|*x_}_", "|(//+._",
"(\\/{>;k"), ID_ZONADUM = c(1622, 1562, 1431, 3792, 1312,
3038, 1673, 1292, 1759, 1274, 3057, 3605, 3708, 1221, 1433,
1365, 1452, 1355, 3377, 3398), ORIGEN = c("SPRO", "SMS",
"SPRO", "SPRO", "SPRO", "SPRO", "SMS", "SPRO", "SPRO", "SPRO",
"SPRO", "SPRO", "SPRO", "SMS", "SPRO", "SPRO", "SPRO", "SPRO",
"SPRO", "SPRO"), ACTIVIDAD = structure(c(6L, 3L, 2L, 2L,
5L, 5L, 3L, 2L, 5L, 5L, 2L, 1L, 2L, 3L, 5L, 2L, 5L, 5L, 5L,
2L), .Label = c("HORECA", "Instalaciones, Mantenimiento y Obra Civil",
"No Spec", "Otros", "Paquetería y transporte urgente", "Pequeño Comercio",
"Supermercados"), class = "factor"), lat = c(41.38308059149,
41.390752258232, 41.395685321124, 41.377472141928, 41.395826426361,
41.391961693047, 41.385461301675, 41.400721690743, 41.3776097494,
41.407150896929, 41.402077667164, 41.393085133204, 41.380250123556,
41.406037037105, 41.39670664047, 41.386903981542, 41.39516783617,
41.388200567422, 41.394411263743, 41.404228695141), lon = c(2.154837049375,
2.154177593286, 2.162988328549, 2.151007353295, 2.172271855917,
2.162611774023, 2.149397960016, 2.174697200163, 2.155300874341,
2.175502512754, 2.177826477447, 2.168626816485, 2.153614884012,
2.181277163321, 2.164337648433, 2.169052711932, 2.166379112099,
2.169668756863, 2.154389212806, 2.172054447565), usetime = c("0 days 00:49:04",
"0 days 00:30:00", "0 days 01:55:37", "0 days 01:04:27",
"0 days 00:14:15", "0 days 00:37:54", "0 days 00:30:00",
"0 days 00:49:55", "0 days 19:18:11", "0 days 00:40:11",
"0 days 00:39:21", "0 days 01:00:26", "0 days 00:55:14",
"0 days 00:30:00", "0 days 00:13:07", "0 days 00:29:47",
"0 days 00:43:04", "0 days 00:37:35", "0 days 00:15:27",
"0 days 00:36:09"), usetime_REAL = c("0 days 00:49:04", "0 days 00:30:00",
"0 days 01:55:37", "0 days 01:04:27", "0 days 00:14:15",
"0 days 00:37:54", "0 days 00:30:00", "0 days 00:49:55",
"0 days 19:18:11", "0 days 00:40:11", "0 days 00:39:21",
"0 days 01:00:26", "0 days 00:55:14", "0 days 00:30:00",
"0 days 00:13:07", "0 days 00:29:47", "0 days 00:43:04",
"0 days 00:37:35", "0 days 00:15:27", "0 days 00:36:09"),
hora_start = c(17, 12, 12, 12, 14, 11, 11, 9, 19, 18, 17,
9, 10, 13, 9, 10, 10, 12, 11, 8), hora_stop = c(18, 12, 14,
13, 14, 12, 11, 10, 14, 18, 17, 10, 11, 14, 9, 10, 10, 13,
11, 8), mes_start = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1), dia_start = c(5, 5, 4, 4, 5, 4,
5, 5, 5, 5, 5, 5, 4, 4, 5, 4, 5, 4, 4, 5), minuto_start = c(31,
25, 57, 22, 36, 52, 6, 37, 24, 8, 6, 43, 5, 34, 12, 12, 1,
47, 11, 12), minuto_stop = c(20, 55, 52, 27, 50, 30, 36,
27, 42, 48, 45, 43, 0, 4, 25, 41, 44, 25, 26, 48), mes = c("Jan",
"Jan", "Jan", "Jan", "Jan", "Jan", "Jan", "Jan", "Jan", "Jan",
"Jan", "Jan", "Jan", "Jan", "Jan", "Jan", "Jan", "Jan", "Jan",
"Jan"), dia_semana = c("Tuesday", "Tuesday", "Monday", "Monday",
"Tuesday", "Monday", "Tuesday", "Tuesday", "Tuesday", "Tuesday",
"Tuesday", "Tuesday", "Monday", "Monday", "Tuesday", "Monday",
"Tuesday", "Monday", "Monday", "Tuesday"), col_5_30 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0),
col_30_120 = c(0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 1, 0, 0), col_120_360 = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), col_max_360 = c(0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), fecha = structure(c(18632,
18632, 18631, 18631, 18632, 18631, 18632, 18632, 18632, 18632,
18632, 18632, 18631, 18631, 18632, 18631, 18632, 18631, 18631,
18632), class = "Date"), time_start = structure(c(63092,
44745, 46636, 44565, 52597, 42727, 39998, 34627, 69843, 65291,
61588, 34998, 36338, 48841, 33148, 36721, 36085, 46063, 40262,
29536), class = c("hms", "difftime"), units = "secs"), fecha_stop = structure(c(18632,
18632, 18631, 18631, 18632, 18631, 18632, 18632, 18633, 18632,
18632, 18632, 18631, 18631, 18632, 18631, 18632, 18631, 18631,
18632), class = "Date"), time_stop = structure(c(66036, 46545,
53573, 48432, 53452, 45001, 41798, 37622, 52934, 67702, 63949,
38624, 39652, 50641, 33935, 38508, 38669, 48318, 41189, 31705
), class = c("hms", "difftime"), units = "secs")), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -20L), spec = structure(list(
cols = list(X1 = structure(list(), class = c("collector_double",
"collector")), FHSTART = structure(list(format = ""), class = c("collector_datetime",
"collector")), FHSTARTREAL = structure(list(format = ""), class = c("collector_datetime",
"collector")), FHSTOPREAL = structure(list(format = ""), class = c("collector_datetime",
"collector")), MATRICULA = structure(list(), class = c("collector_character",
"collector")), ID_ZONADUM = structure(list(), class = c("collector_double",
"collector")), ORIGEN = structure(list(), class = c("collector_character",
"collector")), ACTIVIDAD = structure(list(), class = c("collector_character",
"collector")), LATITUD = structure(list(), class = c("collector_double",
"collector")), LONGITUD = structure(list(), class = c("collector_double",
"collector")), usetime = structure(list(), class = c("collector_character",
"collector")), usetime_REAL = structure(list(), class = c("collector_character",
"collector")), hora_start = structure(list(), class = c("collector_double",
"collector")), hora_stop = structure(list(), class = c("collector_double",
"collector")), mes_start = structure(list(), class = c("collector_double",
"collector")), dia_start = structure(list(), class = c("collector_double",
"collector")), minuto_start = structure(list(), class = c("collector_double",
"collector")), minuto_stop = structure(list(), class = c("collector_double",
"collector")), mes = structure(list(), class = c("collector_character",
"collector")), dia_semana = structure(list(), class = c("collector_character",
"collector")), col_5_30 = structure(list(), class = c("collector_double",
"collector")), col_30_120 = structure(list(), class = c("collector_double",
"collector")), col_120_360 = structure(list(), class = c("collector_double",
"collector")), col_max_360 = structure(list(), class = c("collector_double",
"collector")), fecha = structure(list(format = ""), class = c("collector_date",
"collector")), time_start = structure(list(format = ""), class = c("collector_time",
"collector")), fecha_stop = structure(list(format = ""), class = c("collector_date",
"collector")), time_stop = structure(list(format = ""), class = c("collector_time",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1L), class = "col_spec"))
Related
Transition probability with zero-frequency
With the below code I can calculate the Markov chain probabilities per time step. However I would like to make the following change to my code: a.) speed up the transitions: increase the number of each transition by one AND another change in my code for b.) speed up each transition only between specific time steps (for example 04:10-04:30) Can this be done with Laplace smoothing The mathematical formula for the Laplace smoothing is : where nij represents the count of users whose activity has changed from i to j in the data, and ni represents the count of users whose activity is i at the time step k. The mathematical formula for calculating the transition probability matrixes is: Sample code: library(readr) library(markovchain) mcListFist <- markovchainListFit(data = df[,], name = "df") matrixList <- list() for (i in 1:dim(mcListFist$estimate)) { myMatr <- mcListFist$estimate[[i]]#transitionMatrix matrixList[[i]] <- myMatr } matrixList Sample code: df<-structure(list(`04:00` = c(1, 1, 1, 1, 1, 0, 0, 0, 0, 0), `04:10` = c(1, 1, 0, 0, 0, 0, 0, 0, 0, NA), `04:20` = c(1, 1, 1, 0, 0, 0, 0, 0, 1, NA), `04:30` = c(0, 0, 0, 0, 0, 0, 1, 1, 1, NA)), row.names = c(NA, -10L), spec = structure(list(cols = list(`04:00` = structure(list(), class = c("collector_double", "collector")), `04:10` = structure(list(), class = c("collector_double", "collector")), `04:20` = structure(list(), class = c("collector_double", "collector")), `04:30` = structure(list(), class = c("collector_double", "collector"))), default = structure(list(), class = c("collector_guess", "collector")), delim = ","), class = "col_spec"), problems = <pointer: 0x0000023694f01da0>, class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"))
Making a boxplot based on continuous values
Using 2 classifications, I want to create a boxplot to illustrate the variation in starting and ending times. How I could do this with ggplot? Data structure: Desired output: Sample data: structure(list(day = c("Mo", "Tue", "Wed", "Thur", "Fri", "Mo", "Tue", "Wed", "Thur", "Fri"), start_time1 = c(9.75, 6.5, 6.5, 6.5, 6.5, 8.5, 8.5, 8.5, 8.5, 8.75), end_time1 = c(14.75, 14.75, 8.75, 8.75, 14.75, 17.75, 17.25, 17.25, 16.5, 17.5), Pattern = c(0, 0, 0, 0, 0, 1, 1, 1, 1, 1)), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA, -10L), spec = structure(list( cols = list(day = structure(list(), class = c("collector_character", "collector")), start_time1 = structure(list(), class = c("collector_double", "collector")), end_time1 = structure(list(), class = c("collector_double", "collector")), Pattern = structure(list(), class = c("collector_double", "collector"))), default = structure(list(), class = c("collector_guess", "collector")), skip = 1L), class = "col_spec"))
Is not very clear what you want to do, so I'm trying to guess: Personally, I would put the day on the x-axis, the times on the y-axis, using the colors to differentiate Patterns and facet to differentiate the starting or ending times library(ggplot2) m <- melt(dff,id.vars=c("day","Pattern")) m$Pattern <- as.factor(m$Pattern) ggplot(m,aes(x=day,y=value,fill=Pattern))+ geom_boxplot()+ facet_wrap(~variable)+ labs(y="times") the output depends on the length and variability of the data. With the sample that you provided the output is not so informative. Trying to inject some randomness in the data the plot becomes more useful:
Regression in R on panel data
I would like to run a linear regression on panel data. Below my code so far but, I don't understand why is not returning the fit and rsq. Any suggestion? Sample code: for(i in names(df)) { if(is.numeric(df[3,i])) ##if row 3 is numeric, the entire column is { fit <- lm(df[3,i] ~ Gender, data=df) #does a regression for each column in my csv file against my independent variable 'etch' rsq <- summary(fit)$r.squared } } Data structure Sample data: df<-structure(list(id = c(1, 1, 2, 2, 2), id1 = c(1, 2, 1, 2, 3), a1 = c(5, 8, 7, 6, 3), a2 = c(1, 4, 3, 10, 5), a3 = c(2, 34, 3, 12, 6), a4 = c(9, 2, 3, 12, 7), a5 = c(0, 0, 0, 7, 8), a6 = c(7, 7, 0, 0, 9), a7 = c(5, 8, 7, 6, 0), a8 = c(1, 4, 3, 10, 3), a9 = c(2, 34, 3, 12, 3), a10 = c(9, 2, 3, 12, 3), Gender = c(1, 2, 1, 1, 2)), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA, -5L), spec = structure(list( cols = list(id = structure(list(), class = c("collector_double", "collector")), id1 = structure(list(), class = c("collector_double", "collector")), a1 = structure(list(), class = c("collector_double", "collector")), a2 = structure(list(), class = c("collector_double", "collector")), a3 = structure(list(), class = c("collector_double", "collector")), a4 = structure(list(), class = c("collector_double", "collector")), a5 = structure(list(), class = c("collector_double", "collector")), a6 = structure(list(), class = c("collector_double", "collector")), a7 = structure(list(), class = c("collector_double", "collector")), a8 = structure(list(), class = c("collector_double", "collector")), a9 = structure(list(), class = c("collector_double", "collector")), a10 = structure(list(), class = c("collector_double", "collector")), Gender = structure(list(), class = c("collector_double", "collector"))), default = structure(list(), class = c("collector_guess", "collector")), skip = 1L), class = "col_spec"))
To fit a linear regression on each column you can use lapply. We use reformulate to create a formula object from the column name and use it in lapply. R-squared value can be extracted from summary of each model. cols <- grep('a\\d+', names(df), value = TRUE) cols #[1] "a1" "a2" "a3" "a4" "a5" "a6" "a7" "a8" "a9" "a10" lapply(cols, function(x) { lm(reformulate('Gender', x), df) }) -> fit r.squared <- sapply(fit, function(x) summary(x)$r.squared)
How to summarize a tibble by time periods?
EDIT: I have updated the input, added the expected output. I have a table that contains time-dates and a grouping criterion NEL_Hotspots. I am trying to summarise the table according to these rules: Observations grouped by NEL_Hotspots and then all observations that fall within the same day (24h), AND have Wind_direc within +- 10. This is a small subset of a larger table: structure(list(Serial_number = c(10, 8, 9, 20, 21, 23, 3, 5, 7, 11, 13, 20, 24), Date_time = c("3/31/05 1:57", "3/31/05 4:12", "3/31/05 18:12", "4/1/05 2:12", "4/1/05 3:12", "4/3/05 16:12", "3/28/05 9:57", "3/30/05 13:42", "3/31/05 1:57", "4/10/05 10:57", "4/10/05 18:57", "4/10/05 20:13", "4/10/05 21:30"), Wind_direc = c(50, 60, 70, 60, 70, 70, 60, 140, 50, 270, 300, 310, 290), NEL_Hotspots = c(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1), Dust_Intens = c("weak", "weak", "weak", "weak", "medium", "weak", "weak", "medium", "weak", "weak", "medium", "medium", "high"), Area_km2 = c(290, 241, 225, 240, 340, 320, 176, 143, 211, 72, 171, 167, 121)), .Names = c("Serial_number", "Date_time", "Wind_direc", "NEL_Hotspots", "Dust_Intens", "Area_km2" ), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA, -13L), spec = structure(list(cols = structure(list(Serial_number = structure(list(), class = c("collector_double", "collector")), Date_time = structure(list(), class = c("collector_character", "collector")), Wind_direc = structure(list(), class = c("collector_double", "collector")), NEL_Hotspots = structure(list(), class = c("collector_double", "collector")), Dust_Intens = structure(list(), class = c("collector_character", "collector")), Area_km2 = structure(list(), class = c("collector_double", "collector"))), .Names = c("Serial_number", "Date_time", "Wind_direc", "NEL_Hotspots", "Dust_Intens", "Area_km2")), default = structure(list(), class = c("collector_guess", "collector")), skip = 1), .Names = c("cols", "default", "skip" ), class = "col_spec")) Once the data is loaded I used df <- df %>% mutate(full_date = ymd_hms(Date_time)) from lubridate to create the column full_date. The expected output is: structure(list(`First Date_time` = c("3/31/05 1:57", "3/31/05 18:12", "4/1/05 2:12", "4/3/05 16:12", "3/28/05 9:57", "3/30/05 13:42", "3/31/05 1:57", "4/10/05 10:57", "4/10/05 18:57"), `Last Date_time` = c("3/31/05 4:12", "3/31/05 18:12", "4/1/05 3:12", "4/3/05 16:12", "3/28/05 9:57", "3/30/05 13:42", "3/31/05 1:57", "4/10/05 10:57", "4/10/05 21:30" ), Wind_direc_avg = c(55, 70, 60, 70, 60, 140, 50, 270, 300), wind_direc_min = c(50, 70, 60, 70, 60, 140, 50, 270, 290), wind_direc_max = c(60, 70, 70, 70, 60, 140, 50, 270, 310), NEL_Hotspots = c(0, 0, 0, 0, 1, 1, 1, 1, 1), Dust_Intens = c("weak,weak", "weak", "weak,medium", "weak", "weak", "medium", "weak", "weak", "medium, medium, high"), Area_km2_avg = c(265.5, 225, 290, 320, 176, 143, 211, 72, 153), Area_km2_stdv = c(34.64, 0, 70.71, 0, 0, 0, 0, 0, 27.78), events_count = c(2, 1, 2, 1, 1, 1, 1, 1, 3), serial_numbers = c("10, 8", "9", "20, 21", "23", "3", "5", "7", "11", "13, 20, 24")), .Names = c("First Date_time", "Last Date_time", "Wind_direc_avg", "wind_direc_min", "wind_direc_max", "NEL_Hotspots", "Dust_Intens", "Area_km2_avg", "Area_km2_stdv", "events_count", "serial_numbers"), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA, -9L), spec = structure(list( cols = structure(list(`First Date_time` = structure(list(), class = c("collector_character", "collector")), `Last Date_time` = structure(list(), class = c("collector_character", "collector")), Wind_direc_avg = structure(list(), class = c("collector_double", "collector")), wind_direc_min = structure(list(), class = c("collector_double", "collector")), wind_direc_max = structure(list(), class = c("collector_double", "collector")), NEL_Hotspots = structure(list(), class = c("collector_double", "collector")), Dust_Intens = structure(list(), class = c("collector_character", "collector")), Area_km2_avg = structure(list(), class = c("collector_double", "collector")), Area_km2_stdv = structure(list(), class = c("collector_double", "collector")), events_count = structure(list(), class = c("collector_double", "collector")), serial_numbers = structure(list(), class = c("collector_character", "collector"))), .Names = c("First Date_time", "Last Date_time", "Wind_direc_avg", "wind_direc_min", "wind_direc_max", "NEL_Hotspots", "Dust_Intens", "Area_km2_avg", "Area_km2_stdv", "events_count", "serial_numbers")), default = structure(list(), class = c("collector_guess", "collector")), skip = 1), .Names = c("cols", "default", "skip" ), class = "col_spec")) I would appreciate any help!
Try to create groups based on your condition. A new group is created when - Date changes Every +10 value change in Wind For each group calculate all the statistics that you want in summarise library(dplyr) df %>% mutate(Date_time = lubridate::mdy_hm(Date_time), date = as.Date(Date_time)) %>% group_by(date) %>% group_by(val = lag(ceiling((Wind_direc - first(Wind_direc))/10), default = 0), .add = TRUE) %>% summarise(first_date_time = first(Date_time), last_date_time = last(Date_time), Wind_direc_avg = mean(Wind_direc), Wind_direc_min = min(Wind_direc), Wind_direc_max = max(Wind_direc), NEL_Hotspots = sum(NEL_Hotspots), Dust_Intens = toString(Dust_Intens), Area_km2_avg = mean(Area_km2))
ggplot loop deal with special characters
Hi there I'm trying to plot a defined number of graphs using gridExtra. This is working but unfortunately it is not dealing with special characters in its name. I tried to work around by using R friendly names and add in the actual name as a subtitle library(gridExtra) library(ggplot2) Dataframe<-read.csv2(File_with_R_friendly_names.csv) names<-read.csv2(File_with_actual_names.csv) bar<-colnames(names) list_of_plots<-lapply(names(Dataframe)[2:10], function(i) { ggplot(Dataframe, aes_string(x="X1", y=i)) + geom_point()+labs(x=i, y="Intensity", subtitle=bar[i]) }) do.call(grid.arrange, c(list_of_plots, ncol=3)) If I put in bar[2] all graphs get the actual name but it is the same one for all while if I set bar to i, all graphs get NA. The names I use to suit R are Met1, Met2, Met3, Met4, Met5, Met6, Met7, Met8, Met9 and Met10 Examples of names that I need on the plots are: -(-)-Corey lactone -(2R)-2,3-Dihydroxypropanoic acid -(D-(+)-Glyceric acid?) -1,5-Naphthalenediamine -12-Aminododecanoic acid -2,5-di-tert-Butylhydroquinone -2,6-di-tert-Butylphenol -2-Amino-N,N-diethylacetamide -2-Ethyl-2-phenylmalonamide -2-Naphthalenesulfonic acid Here is the dput to reproduce the bar (names): `bar<-c("X1", "(-)-Corey lactone", "(2R)-2,3-Dihydroxypropanoic acid (D-(+)- Glyceric acid?)", "1,5-Naphthalenediamine", "12-Aminododecanoic acid", "2,5-di- tert-Butylhydroquinone", "2,6-di-tert-Butylphenol", "2-Amino-N,N- diethylacetamide", "2-Ethyl-2-phenylmalonamide", "2-Naphthalenesulfonic acid")` Here is the dput to reproduce the dataframe: Dataframe<-structure(list(X1 = c(0, 0, 0.25, 0.25, 0.5, 0.5, 1, 1, 2, 2), Met1 = c(0, 0, 38096319.85, 45978353.93, 35077691.7, 42146132.41, 62606961.17, 32786049.6, 51054004.82, 48898547.32), Met2 = c(0, 0, 1288905.771, 948466.4001, 645979.6463, 1228663.251, 1137957.136, 940928.9344, 1443680.706, 1755726.385), Met3 = c(0, 0, 575887.464, 693692.0349, 1362477.6, 1515767.293, 2241120.502, 2417932.908, 3866432.112, 3894701.876), Met4 = c(0, 0, 16737068.73, 21915551.3, 12088089.1, 16003037.3, 17720785.29, 11957614.24, 13127281.5, 14192542.13), Met5 = c(0, 0, 4556006.426, 4782909.936, 4484706.271, 8019957.826, 5112289.476, 8537488.48, 6680688.948, 5959748.061 ), Met6 = c(0, 0, 16874476.32, 15721984.25, 18093323.61, 18619817.92, 22055835.04, 19754379.11, 29211315.88, 27321333.35 ), Met7 = c(0, 0, 6604385.457, 6396794.568, 13823034.64, 15449539.63, 26013299.82, 20262673.28, 35301685.57, 33367520.66 ), Met8 = c(0, 0, 6727973.448, 7166827.569, 13238311.46, 13986568.69, 20957194.23, 19186953.76, 34513697.47, 31192991.75 ), Met9 = c(0, 0, 2373752.304, 3259738.104, 1998529.732, 2387445.15, 2479309.442, 26924139.6, 4611277.427, 2439602.098 )), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -10L), .Names = c("X1", "Met1", "Met2", "Met3", "Met4", "Met5", "Met6", "Met7", "Met8", "Met9"), spec = structure(list(cols = structure(list( X1 = structure(list(), class = c("collector_double", "collector" )), Met1 = structure(list(), class = c("collector_double", "collector")), Met2 = structure(list(), class = c("collector_double", "collector")), Met3 = structure(list(), class = c("collector_double", "collector")), Met4 = structure(list(), class = c("collector_double", "collector")), Met5 = structure(list(), class = c("collector_double", "collector")), Met6 = structure(list(), class = c("collector_double", "collector")), Met7 = structure(list(), class = c("collector_double", "collector")), Met8 = structure(list(), class = c("collector_double", "collector")), Met9 = structure(list(), class = c("collector_double", "collector"))), .Names = c("X1", "Met1", "Met2", "Met3", "Met4", "Met5", "Met6", "Met7", "Met8", "Met9")), default = structure(list(), class = c("collector_guess", "collector"))), .Names = c("cols", "default"), class = "col_spec"))
Because names(Dataframe)[2:10] is not number. Below will work: list_of_plots<-lapply(as.numeric(names(Dataframe)[2:10]), function(i) { ggplot(Dataframe, aes_string(x="X1", y=i)) + geom_point()+labs(x=i, y="Intensity", subtitle=bar[i]) }) do.call(grid.arrange, c(list_of_plots, ncol=3))