Rotating through multiple Y Variables in gganimate - r

I'm currently trying to animate a plot using gganimate but am struggling to figure out how I would rotate through multiple y variables. The following data was collected from twitter scraping which allowed me to calculate a "sentiment score" based on the tweets following the recent Democratic debate. The goal here is to create an animated plot that eases through all 10 sentiment scores and adjusts the ggplot for each candidate. Is this possible with gganimate?
structure(
list(
candidate = c("warren", "booker", "yang", "harris", "biden", "sanders", "buttigieg"),
anger = c(162, 216, 193, 74, 451, 290, 114),
anticipation = c(570, 492, 401, 205, 360, 419, 499),
disgust = c(94, 75, 52, 61, 202, 81, 69),
fear = c(245, 241, 119, 117, 271, 251, 102),
joy = c(574, 525, 279, 181, 214, 319, 183),
sadness = c(237, 161, 138, 106, 406, 157, 251),
surprise = c(104, 191, 176, 106, 255, 343, 123),
trust = c(741, 749, 460, 325, 593, 574, 410),
negative = c(540, 317, 253, 205, 715, 360, 469),
positive = c(989, 1202, 857, 510, 751, 790, 701)
),
class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"),
row.names = c(NA, -7L),
spec = structure(
list(
cols = list(
candidate = structure(list(), class = c("collector_character", "collector")),
anger = structure(list(), class = c("collector_double", "collector")),
anticipation = structure(list(), class = c("collector_double", "collector")),
disgust = structure(list(), class = c("collector_double", "collector")),
fear = structure(list(), class = c("collector_double", "collector")),
joy = structure(list(), class = c("collector_double", "collector")),
sadness = structure(list(), class = c("collector_double", "collector")),
surprise = structure(list(), class = c("collector_double", "collector")),
trust = structure(list(), class = c("collector_double", "collector")),
negative = structure(list(), class = c("collector_double", "collector")),
positive = structure(list(), class = c("collector_double", "collector"))),
default = structure(list(), class = c("collector_guess", "collector")), skip = 1
),
class = "col_spec")
)
Here is the script I currently have written:
library ("ggplot2")
library("dplyr")
library("tidyverse")
library("plotly")
library("viridis")
library("gganimate")
#Read in CSV Files
sentiment_score <- read_csv('C:\\Users\\tdago\\Documents\\R\\Sentiment_Scores.csv')
sentiment_score_hashtag <- read_csv('C:\\Users\\tdago\\Documents\\R\\Sentiment_Scores_hashtag.csv')
#Tidy Data
sentiment_score <- sentiment_score %>%
rename(candidate = X1)
sentiment_score_hashtag <-sentiment_score_hashtag %>%
rename(candidate = X1)
#Create Charts for Comparison
ggplot(data=sentiment_score,aes(x = candidate, y=anger))+
geom_bar(aes(fill=candidate),stat = "identity")+
theme(legend.position="none")+
xlab("Presidential Candidates")+ylab("Scores")+ggtitle("Anger") +
labs(x = "", y = "{sentiment"}) +
ease_aes('linear')
Note: the sentiment_score object is the only one that is being used in this specific chart. sentiment_score_hashtag is a similar data frame that contains sentiment scores based on a different search.

I don't think you can rotate through Y variables with gganimate. Is easier to transform your data from wide to long format (see this question for a comprehensive list of methods to achieve this). I will go with the tidy way, using tidyr::pivot_longer:
> sentiment_score %>%
+ pivot_longer(-candidate, names_to = 'sentiment')
# A tibble: 70 x 3
candidate sentiment value
<chr> <chr> <dbl>
1 warren anger 162
2 warren anticipation 570
3 warren disgust 94
4 warren fear 245
5 warren joy 574
6 warren sadness 237
7 warren surprise 104
8 warren trust 741
9 warren negative 540
10 warren positive 989
# … with 60 more rows
>
This way, you can use easily sentiment as a state variable in gganimate, and follow the nice gganimate getting started manual.
Here is an example of the possibilities:
library ("ggplot2")
library("dplyr")
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library("tidyverse")
# library("plotly")
# library("viridis")
library("gganimate")
#Tidy Data
sentiment_score <- structure(
list(
candidate = c("warren", "booker", "yang", "harris", "biden", "sanders", "buttigieg"),
anger = c(162, 216, 193, 74, 451, 290, 114),
anticipation = c(570, 492, 401, 205, 360, 419, 499),
disgust = c(94, 75, 52, 61, 202, 81, 69),
fear = c(245, 241, 119, 117, 271, 251, 102),
joy = c(574, 525, 279, 181, 214, 319, 183),
sadness = c(237, 161, 138, 106, 406, 157, 251),
surprise = c(104, 191, 176, 106, 255, 343, 123),
trust = c(741, 749, 460, 325, 593, 574, 410),
negative = c(540, 317, 253, 205, 715, 360, 469),
positive = c(989, 1202, 857, 510, 751, 790, 701)
),
class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"),
row.names = c(NA, -7L),
spec = structure(
list(
cols = list(
candidate = structure(list(), class = c("collector_character", "collector")),
anger = structure(list(), class = c("collector_double", "collector")),
anticipation = structure(list(), class = c("collector_double", "collector")),
disgust = structure(list(), class = c("collector_double", "collector")),
fear = structure(list(), class = c("collector_double", "collector")),
joy = structure(list(), class = c("collector_double", "collector")),
sadness = structure(list(), class = c("collector_double", "collector")),
surprise = structure(list(), class = c("collector_double", "collector")),
trust = structure(list(), class = c("collector_double", "collector")),
negative = structure(list(), class = c("collector_double", "collector")),
positive = structure(list(), class = c("collector_double", "collector"))),
default = structure(list(), class = c("collector_guess", "collector")), skip = 1
),
class = "col_spec")
)
#Create Charts for Comparison
candidates_plot <- sentiment_score %>%
pivot_longer(-candidate, names_to = 'sentiment') %>%
ggplot(aes(x = candidate, y=value))+
geom_bar(aes(fill=candidate, group = sentiment),stat = "identity")+
scale_y_continuous(expand = c(0,0), limits = c(0,1250)) +
theme(legend.position="none")#+
# xlab("Presidential Candidates")+ylab("Scores")+ggtitle("{sentiment}") +
# labs(x = "Presidential Candidates", y = "{sentiment}")
anim <- candidates_plot +
transition_states(
sentiment, 2, 2
) +
enter_fade() + enter_drift(y_mod = -500) +
exit_shrink() + exit_drift(y_mod = -500) +
labs(
title = '{closest_state}',
x = "Presidential Candidates", y = "{closest_state}"
)
animate(
anim, width = 500, height = 300, res = 90
)
Created on 2019-11-25 by the reprex package (v0.3.0)

Related

Loop in tidyverse

I am learning tidyverse() and I am using a time-series dataset, and I selected columns that start with sec. What I would like basically to identify those values from columns that equal 123, keep these and have the rest replace with 0. But I don't know how to loop from sec1:sec4. Also how can I sum() per columns?
df1<-df %>%
select(starts_with("sec")) %>%
select(ifelse("sec1:sec4"==123, 1, 0))
Sample data:
structure(list(sec1 = c(1, 123, 1), sec2 = c(123, 1, 1), sec3 = c(123,
0, 0), sec4 = c(1, 123, 1)), spec = structure(list(cols = list(
sec1 = structure(list(), class = c("collector_double", "collector"
)), sec2 = structure(list(), class = c("collector_double",
"collector")), sec3 = structure(list(), class = c("collector_double",
"collector")), sec4 = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), row.names = c(NA,
-3L), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"))
I think you would have to use mutate and across to accomplish this. below you will mutate across each column starting with sec and then keep all values that are 123 and replace all others with 0.
df1<-df %>%
select(starts_with("sec")) %>%
mutate(across(starts_with("sec"),.fns = function(x){ifelse(x == 123,x,0)}))

Bubble plot for three observation

This my data. I m trying to put three column in my bubbleplot.
They are Altered, Unaltered and the associated survial q value
My data frame
dput(df)
structure(list(Class = c("cell fate commitment", "chromatin remodeling",
"chromatin_covalent", "demethylation", "histone methylation",
"intracellular receptor signaling pathway", "negative regulation of cell differentiation",
"Nuclear Receptor transcription pathway", "PID HDAC CLASSI PATHWAY",
"PID SMAD2 3NUCLEAR PATHWAY", "regulation of chromatin organization",
"Transcriptional misregulation in cancer"), Altered = c(182,
312, 433, 117, 354, 294, 258, 268, 244, 185, 197, 282), Unaltered = c(489,
361, 235, 559, 315, 370, 411, 409, 426, 491, 483, 387), `q-Value` = c(0.0009732,
1.1e-07, 2.832e-05, 0.137, 0.003188, 0.971, 0.139, 0.0008647,
0.002938, 2.843e-06, 3.102e-06, 0.032)), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -12L), spec = structure(list(
cols = list(Class = structure(list(), class = c("collector_character",
"collector")), Altered = structure(list(), class = c("collector_double",
"collector")), Unaltered = structure(list(), class = c("collector_double",
"collector")), `q-Value` = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1L), class = "col_spec"))
Code for the plot
xm <- reshape2::melt(df, id.vars = "Class", variable.name = "Samples", value.name = "Size")
# Calculate bubble size
bubble_size <- function(val){
ifelse(val > 3, (1/15) * val + (1/3), val)
}
# Calculate bubble colour
bubble_colour <- function(val){
ifelse(val > 3, "A", "B")
}
# Calculate bubble size and colour
xm %<>%
mutate(bub_size = bubble_size(Size),
bub_col = bubble_colour(Size))
# Plot data
ggplot(xm, aes(x = Samples, y = fct_rev(Class))) +
geom_point(aes(size = bub_size, fill = bub_col), shape = 21, colour = "black") +
# geom_text()
geom_label_repel(aes(label=Size), size=3)+
theme(panel.grid.major = element_line(colour = alpha("gray", 0.5), linetype = "dashed"),
text = element_text(family = "serif"),
legend.position = "none") +
scale_size(range = c(1, 25)) +
scale_fill_manual(values = c("blue","red")) +
ylab("Class")
I get something like this
How do I label the two patient group into different color as well as label the data point such as patient number for both group and the qualue in the plot
Update
I can put label into the plot. But not able to map two different colors for the patient group altered and unaltered group.
Updated fig

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))

Unexpected behavior of filter inside a function dplyr

I have a function that filters a data.frame based on the unique values of a group column that is passed to the function
la <- function(df, grp){
gr <- df %>% pull({{grp}}) %>% unique()
purrr::map(gr, function(x){
print(x)
filter(df, {{grp}} == x)
})
}
When I use it with this df,
x <- structure(list(mac = c("dc:a6:32:21:59:2b", "dc:a6:32:2d:8c:ca",
"dc:a6:32:2d:b8:62", "dc:a6:32:2d:ca:3f"), datetime = structure(c(1594644546,
1594645457, 1594645375, 1594645080), tzone = "UTC", class = c("POSIXct",
"POSIXt")), Comment = c("FED2", "FED7", "FED1", "FED6")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -4L))
la(x, mac)
I get the proper prints and the subsets.
However, when I use it with this other df, which should be equivalent, it doesn't work as expected.
df <- structure(list(datetime = structure(c(1594644600, 1594644900,
1594645200, 1594645500, 1594645800, 1594646100), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), movement = c(9940.50454596681, 10779.7747307276,
7148.52826988968, 7687.54314683339, 8797.06954533588, 7524.02474093548
), x = c(606, NA, 240, NA, 504, NA), y = c(386, NA, 274, NA,
56, NA), i_x = c(606, 228, 214, 407.5, 500, 292.947368421053),
i_y = c(386, 286, 258, 49.1666666666667, 56, 234), mac = c("dc:a6:32:21:59:2b",
"dc:a6:32:21:59:2b", "dc:a6:32:21:59:2b", "dc:a6:32:21:59:2b",
"dc:a6:32:21:59:2b", "dc:a6:32:21:59:2b")), spec = structure(list(
cols = list(filename = structure(list(), class = c("collector_character",
"collector")), datetime = structure(list(format = ""), class = c("collector_datetime",
"collector")), movement = structure(list(), class = c("collector_double",
"collector")), x = structure(list(), class = c("collector_double",
"collector")), y = structure(list(), class = c("collector_double",
"collector")), i_x = structure(list(), class = c("collector_double",
"collector")), i_y = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = "\t"), class = "col_spec"), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
I get 0 rows on each type of group (my real example has the same groups as the ones for the x dataframe).
Interestingly, this works as expected.
la(select(head(df), mac, datetime), mac)
[1] "dc:a6:32:21:59:2b"
[[1]]
# A tibble: 6 x 2
mac datetime
<chr> <dttm>
1 dc:a6:32:21:59:2b 2020-07-13 12:50:00
2 dc:a6:32:21:59:2b 2020-07-13 12:55:00
3 dc:a6:32:21:59:2b 2020-07-13 13:00:00
4 dc:a6:32:21:59:2b 2020-07-13 13:05:00
5 dc:a6:32:21:59:2b 2020-07-13 13:10:00
6 dc:a6:32:21:59:2b 2020-07-13 13:15:00
What is going on?
As the comment suggests, the problem is that I have function(x) inside the map call and because df has an x column, things become weird. I chose another variable name for that, and now it's working.
la <- function(df, grp){
gr <- df %>% pull({{grp}}) %>% unique()
purrr::map(gr, function(tt){
print(tt)
filter(df, {{grp}} == tt)
})
}

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))

Resources