I want to plot under two X,Y axis
The first one would have X axis Timecode and Y as the cumul of each line as line =1 across Timecode
The biggest axis is Y as Sample_Hour and X as Type
df=structure(list(Sample_ID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L
), Sample_Hour = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
), .Label = c("17:03:13", "17:05:44", "17:08:44", "17:11:39",
"17:14:39", "17:18:06", "17:21:13", "17:24:02", "17:27:05", "17:32:43",
"17:35:59", "17:38:40", "17:41:26", "17:44:43", "17:48:14", "17:51:14",
"17:55:00", "17:57:16", "18:00:12", "18:03:16", "18:06:03", "18:09:59",
"18:12:49", "18:15:37", "18:18:01", "18:21:31", "18:26:09", "18:27:58",
"18:29:52", "18:33:21", "18:36:40", "18:38:50", "18:41:25", "18:44:35",
"18:48:45", "18:52:08", "18:54:19", "18:59:52", "19:02:28", "19:06:04",
"19:11:18", "19:15:03", "19:18:06", "19:21:37"), class = "factor"),
Direction = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), Timecode = structure(c(1545667346,
1545667367, 1545667368, 1545667369, 1545667370, 1545667379,
1545667382, 1545667383, 1545667387, 1545667390, 1545667391,
1545667482, 1545667482, 1545667483, 1545667483, 1545667483,
1545667483, 1545667483, 1545667483, 1545667484, 1545667484,
1545667484, 1545667484, 1545667484, 1545667484, 1545667484,
1545667484, 1545667484, 1545667484, 1545667484, 1545667484,
1545667484, 1545667484, 1545667485, 1545667485, 1545667485,
1545667485, 1545667485, 1545667485, 1545667485, 1545667485,
1545667485, 1545667485, 1545667485, 1545667485, 1545667485,
1545667485, 1545667486, 1545667486, 1545667486, 1545667486,
1545667486, 1545667486, 1545667486, 1545667486, 1545667486,
1545667486, 1545667486, 1545667487, 1545667487, 1545667487,
1545667487, 1545667487, 1545667487, 1545667487, 1545667487,
1545667487, 1545667487, 1545667487, 1545667487, 1545667487,
1545667487, 1545667488, 1545667488, 1545667488, 1545667488,
1545667488, 1545667488, 1545667488, 1545667488, 1545667488,
1545667489, 1545667489, 1545667489, 1545667489, 1545667489,
1545667489, 1545667489, 1545667490, 1545667490, 1545667490,
1545667490, 1545667491, 1545667491, 1545667491, 1545667491,
1545667491, 1545667491, 1545667491, 1545667492, 1545667492,
1545667493, 1545667493, 1545667493, 1545667494, 1545667494,
1545667494, 1545667494, 1545667495, 1545667495, 1545667496,
1545667497, 1545667497, 1545667498, 1545667498, 1545667498,
1545667498, 1545667499, 1545667499, 1545667500, 1545667500,
1545667501, 1545667501, 1545667501, 1545667502, 1545667503,
1545667503, 1545667503, 1545667504, 1545667504, 1545667504,
1545667504, 1545667505, 1545667505, 1545667505, 1545667505,
1545667505, 1545667506, 1545667506, 1545667506, 1545667507,
1545667507, 1545667507, 1545667508, 1545667508, 1545667509,
1545667509, 1545667509, 1545667509, 1545667510, 1545667510,
1545667510, 1545667510, 1545667510, 1545667511, 1545667511,
1545667511, 1545667512, 1545667512, 1545667512, 1545667513,
1545667513, 1545667514, 1545667514, 1545667514, 1545667515,
1545667515, 1545667516, 1545667516, 1545667516, 1545667516,
1545667517, 1545667517, 1545667517, 1545667518, 1545667518,
1545667518, 1545667519, 1545667520, 1545667520, 1545667521,
1545667521, 1545667522, 1545667522, 1545667522, 1545667522,
1545667522, 1545667523, 1545667523, 1545667523, 1545667523,
1545667523, 1545667524, 1545667524, 1545667524, 1545667524,
1545667524, 1545667525, 1545667525, 1545667526), class = c("POSIXct",
"POSIXt"), tzone = ""), Type = c("14", "1", "6", "14", "4",
"6", "14", "6", "4", "1", "6", "5", "6", "1", "8", "5", "4",
"7", "2", "2", "6", "5", "16", "8", "3", "5", "1", "1", "8",
"7", "9", "6", "11", "7", "5", "4", "9", "6", "5", "2", "1",
"12", "4", "4", "14", "14", "12", "7", "1", "6", "3", "4",
"5", "2", "12", "4", "5", "2", "9", "1", "14", "7", "1",
"4", "12", "5", "7", "14", "3", "5", "2", "9", "14", "4",
"6", "1", "2", "5", "4", "3", "9", "3", "1", "9", "4", "4",
"3", "1", "4", "4", "7", "1", "3", "4", "7", "1", "6", "4",
"4", "14", "14", "4", "4", "4", "14", "4", "4", "4", "4",
"6", "4", "1", "4", "7", "6", "7", "14", "7", "6", "7", "4",
"6", "4", "7", "6", "4", "7", "4", "7", "7", "1", "7", "6",
"14", "7", "4", "4", "6", "6", "7", "4", "4", "6", "7", "4",
"7", "4", "7", "4", "6", "7", "4", "4", "1", "6", "4", "4",
"6", "4", "4", "6", "4", "14", "6", "6", "6", "7", "4", "6",
"7", "4", "7", "4", "6", "14", "6", "1", "6", "7", "6", "6",
"4", "6", "6", "7", "7", "6", "7", "7", "6", "4", "1", "7",
"7", "14", "6", "7", "7", "6", "7"), Duration = c(0, 0, 0,
23, 0, 11, 13, 4, 17, 23, 8, 0, 0, 0, 0, 1, 0, 0, 0, 1, 2,
1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 2, 1, 1, 0, 1,
1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 1, 0, 0, 0, 2,
1, 2, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 2, 1, 1, 1,
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 3, 1, 2, 1, 1, 1, 3,
0, 0, 4, 0, 2, 0, 0, 2, 1, 0, 0, 1, 4, 1, 6, 1, 7, 3, 0,
4, 1, 1, 1, 3, 2, 1, 1, 1, 2, 2, 0, 1, 0, 7, 0, 3, 7, 1,
2, 0, 1, 0, 1, 2, 0, 1, 2, 1, 1, 1, 0, 0, 3, 1, 1, 0, 6,
1, 1, 0, 1, 1, 0, 1, 1, 9, 1, 0, 1, 5, 3, 1, 1, 0, 1, 1,
1, 4, 1, 8, 1, 3, 1, 1, 4, 1, 0, 2, 0, 0, 1, 0, 1, 2, 5,
1, 0, 6, 1, 0, 1, 1, 1)), .Names = c("Sample_ID", "Sample_Hour",
"Direction", "Timecode", "Type", "Duration"), row.names = c(NA,
-200L), class = c("tbl_df", "tbl", "data.frame"))
dplyr-approach
first, create a table with an increasing 1 per group (=cumsum of observations/persons)
result <- df %>%
group_by( Sample_ID, Type ) %>%
mutate( nb = 1:n() )
then create a facetted lins/point plot.
The free_x in the facet_grid keeps the result readable. You have to set the axis-labels/breaks manually
ggplot( data = result, aes( x = Timecode, y = nb ) ) +
geom_line( aes( group = 1 ), size = 1 ) +
geom_point() +
facet_grid( Type ~ Sample_ID, scales = "free_x" ) +
scale_x_datetime( date_breaks = "10 secs", labels = date_format( "%H:%M:%S", tz = "" ) ) +
theme(axis.text.x = element_text( angle = 90, vjust = 0.5, hjust = 1 ) )
Related
First time I ever cared to sort because I need to report this in a specific way. Typically, smallest to largest sort in excel on column quarter returns YTD, 3,2,1. etc. However, I cannot sort using Order(-begin$Quarter) or rev(begin$Quarter). Other solutions with mix sort prevent me from then also sorting other columns, like here I want to sort by quarter then segment. I have dput examples.
Thanks,
begin<- structure(list(Quarter = structure(c(1L, 1L, 1L, 2L, 2L, 2L,
3L, 3L, 3L, 4L, 4L, 4L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L,
4L, 4L), .Label = c("1", "2", "3", "YTD"), class = "factor"),
Segment = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
), .Label = c("Beverages", "Food"), class = "factor"), Person = structure(c(3L,
2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L,
2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L), .Label = c("Chris", "Jackie",
"Josh"), class = "factor"), Sales = c(4, 4, 3, 2, 3, 3, 7,
7, 1, 1, 2, 3, 7, 7, 8, 5, 7, 8, 9, 6, 6, 7, 5, 6)), class = "data.frame", row.names = c(NA,
-24L))
end<- structure(list(Quarter = structure(c(4L, 4L, 4L, 4L, 4L, 4L,
3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = c("1", "2", "3", "YTD"), class = "factor"),
Segment = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L
), .Label = c("Beverages", "Food"), class = "factor"), Person = structure(c(1L,
1L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 2L,
3L, 3L, 1L, 1L, 2L, 2L, 3L, 3L), .Label = c("Chris", "Jackie",
"Josh"), class = "factor"), Sales = c(3, 6, 2, 5, 1, 7, 1,
6, 7, 6, 7, 9, 3, 8, 3, 7, 2, 5, 3, 8, 4, 7, 4, 7)), class = "data.frame", row.names = c(NA,
-24L))
library(dplyr)
begin %>%
arrange(desc(Quarter), Person, Segment)
I am trying to figure out a way of introducing negative values of factors in a stacked barplot in ggplot2. The data is level of support for basic income among Finnish MPs. It is at the bottom of the post.
I can get a plot that is like the one I want (minus the negatively valued factors) with the following code:
library(forcats)
library(ggplot2)
support.plot <- ggplot(mpsupport.df, aes(fct_infreq(Party))) +
geom_bar (aes(fill=Support)) +
coord_flip() +
theme(legend.position = "bottom")+
ylab("Party") +
xlab("Number of MPs")
This gives the following:
What I would like is for the graph to be centred on the green-turquoise border, so that support for basic income was to the right, while opposition was to the left. Does this make sense?
Data:
> dput(mpsupport.df)
structure(list(Party = structure(c(1L, 2L, 2L, 2L, 2L, 2L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L,
3L, 3L, 3L, 3L, 3L, 5L, 6L, 7L, 7L, 7L), .Label = c("National Coalition",
"Centre Party", "Social Democratic Party", "Left Alliance", "Christian Democrats",
"True Finns", "Swedish People's Party", "Greens"), class = "factor"),
Support = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L), .Label = c("fully.agree", "partially.agree",
"partially.disagree", "fully.disagree"), class = "factor")), .Names = c("Party",
"Support"), row.names = c("1", "2", "2.1", "2.2", "2.3", "2.4",
"4", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6", "4.7", "6", "8",
"8.1", "8.2", "8.3", "8.4", "8.5", "8.6", "8.7", "8.8", "8.9",
"8.10", "8.11", "8.12", "8.13", "8.14", "9", "9.1", "9.2", "9.3",
"9.4", "9.5", "9.6", "9.7", "10", "10.1", "10.2", "10.3", "10.4",
"10.5", "10.6", "10.7", "10.8", "10.9", "10.10", "10.11", "10.12",
"10.13", "10.14", "10.15", "10.16", "10.17", "10.18", "10.19",
"10.20", "10.21", "10.22", "10.23", "10.24", "10.25", "10.26",
"10.27", "10.28", "10.29", "10.30", "10.31", "10.32", "10.33",
"11", "11.1", "11.2", "11.3", "12", "12.1", "12.2", "12.3", "13",
"14", "14.1", "14.2", "14.3", "14.4", "14.5", "14.6", "14.7",
"14.8", "14.9", "14.10", "14.11", "14.12", "14.13", "14.14",
"14.15", "14.16", "14.17", "14.18", "14.19", "14.20", "15", "15.1",
"17", "17.1", "17.2", "17.3", "17.4", "17.5", "17.6", "17.7",
"17.8", "17.9", "17.10", "17.11", "17.12", "17.13", "17.14",
"17.15", "17.16", "17.17", "17.18", "17.19", "18", "18.1", "18.2",
"18.3", "18.4", "18.5", "18.6", "18.7", "19", "19.1", "19.2",
"19.3", "19.4", "19.5", "19.6", "19.7", "19.8", "19.9", "19.10",
"19.11", "19.12", "19.13", "19.14", "19.15", "19.16", "19.17",
"19.18", "19.19", "19.20", "19.21", "19.22", "19.23", "21", "21.1",
"22", "22.1", "22.2", "22.3", "22.4", "22.5", "22.6", "22.7",
"22.8", "22.9", "22.10", "22.11", "22.12", "23", "23.1", "23.2",
"23.3", "25", "25.1", "25.2", "25.3", "25.4", "25.5", "25.6",
"27", "27.1", "27.2", "27.3", "27.4", "27.5", "29", "30", "31",
"31.1", "31.2"), class = "data.frame")
Try something along these lines:
library(ggplot)
library(forcats)
mpsupport.df$dummy = ifelse(mpsupport.df$Support %in% c("fully.agree", "partially.agree"), 1, -1)
agg = aggregate(dummy ~ Support + Party, data = mpsupport.df, FUN = sum)
ggplot(data = agg)+
geom_bar (aes(y = dummy, x= fct_infreq(Party), fill = factor(Support, levels = c("fully.agree", "partially.agree", "fully.disagree" ,"partially.disagree"))), stat= "identity") +
coord_flip()+
theme(legend.position = "bottom", legend.title = element_blank())
Here is an image of my plot so far. At the end of the post I provide the code to reproduce it.
For the time being i use horizontal lines to separate the four groups of lines (defined by variable de in the dataframe). But I would like to use colored rectangles in the background of each group. See the following image to get an idea.
I tried geom_rect and geom_tile with no success. Could anybody help me?
mdfr<-structure(list(name = structure(c(13L, 13L, 13L, 14L, 14L, 14L,
1L, 1L, 1L, 10L, 10L, 10L, 7L, 7L, 7L, 2L, 2L, 2L, 15L, 15L,
15L, 8L, 8L, 8L, 11L, 11L, 11L, 16L, 16L, 16L, 4L, 4L, 4L, 12L,
12L, 12L, 9L, 9L, 9L, 17L, 17L, 17L, 5L, 5L, 5L, 6L, 6L, 6L,
3L, 3L, 3L, 13L, 13L, 13L, 14L, 14L, 14L, 1L, 1L, 1L, 10L, 10L,
10L, 7L, 7L, 7L, 2L, 2L, 2L, 15L, 15L, 15L, 8L, 8L, 8L, 11L,
11L, 11L, 16L, 16L, 16L, 4L, 4L, 4L, 12L, 12L, 12L, 9L, 9L, 9L,
17L, 17L, 17L, 5L, 5L, 5L, 6L, 6L, 6L, 3L, 3L, 3L, 13L, 13L,
14L, 14L, 1L, 1L, 10L, 10L, 7L, 7L, 2L, 2L, 15L, 15L, 8L, 8L,
11L, 11L, 16L, 16L, 4L, 4L, 12L, 12L, 9L, 9L, 17L, 17L, 5L, 5L,
6L, 6L, 3L, 3L), .Label = c("10012/06", "541/13", "700-1/15",
"700/13", "737/13", "751/15", "512/12", "579/13", "715/14", "458/07",
"635/13", "705/13, \n705-1/15", "10004/07", "10005/07", "563/09",
"698/16", "717/14"), class = "factor"), Contr.finish = structure(c(1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Initial", "Current",
"Forecast", "Cost"), class = "factor"), variable = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("start_date", "end_date"
), class = "factor"), value = c("2007-05-30", "2009-03-30", "2016-06-29",
"2007-09-05", "2010-03-05", "2017-09-30", "2006-09-26", "2008-09-26",
"2015-08-31", "2007-11-20", "2011-11-20", "2014-03-20", "2012-01-31",
"2014-07-31", "2016-03-20", "2013-06-21", "2016-06-21", "2016-06-21",
"2009-04-15", "2011-04-15", "2017-12-31", "2013-06-21", "2016-06-21",
"2016-06-21", "2013-12-18", "2016-08-18", "2017-08-18", "2016-04-14",
"2018-02-14", "2018-02-14", "2013-06-03", "2014-10-03", "2016-05-10",
"2013-08-07", "2015-02-07", "2016-06-30", "2014-09-11", "2016-09-11",
"2016-09-11", "2014-09-26", "2016-09-26", "2016-09-26", "2013-03-20",
"2016-03-20", "2016-03-20", "2015-10-09", "2016-08-09", "2016-08-09",
"2015-11-10", "2016-05-10", "2016-05-10", "2009-03-30", "2016-06-29",
"2016-06-29", "2010-03-05", "2017-09-30", "2017-09-30", "2008-09-26",
"2015-08-31", "2016-08-31", "2011-11-20", "2014-03-20", "2015-12-31",
"2014-07-31", "2016-03-20", "2016-12-20", "2016-06-21", "2016-06-21",
"2016-12-30", "2011-04-15", "2017-12-31", "2017-12-31", "2016-06-21",
"2016-06-21", "2018-03-31", "2016-08-18", "2017-08-18", "2018-02-28",
"2018-02-14", "2018-02-14", "2018-02-14", "2014-10-03", "2016-05-10",
"2016-05-10", "2015-02-07", "2016-06-30", "2016-06-30", "2016-09-11",
"2016-09-11", "2017-07-28", "2016-09-26", "2016-09-26", "2016-09-26",
"2016-03-20", "2016-03-20", "2018-10-19", "2016-08-09", "2016-08-09",
"2016-08-09", "2016-05-10", "2016-05-10", "2016-05-10", "2007-05-30",
"2013-09-24", "2007-09-05", "2010-10-21", "2006-09-26", "2016-08-02",
"2007-11-20", "2015-10-19", "2012-01-31", "2015-11-23", "2013-06-21",
"2015-06-09", "2009-04-15", "2014-05-06", "2013-06-21", "2015-03-28",
"2013-12-18", "2015-05-24", "2016-04-14", "2016-04-14", "2013-06-03",
"2016-01-07", "2013-08-07", "2015-12-08", "2014-09-11", "2015-07-24",
"2014-09-26", "2015-06-18", "2013-03-20", "2017-02-22", "2015-10-09",
"2015-10-09", "2015-11-10", "2016-01-06"), bar = c(5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2.5, 2.5, 2.5, 2.5,
2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5,
2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5,
2.5, 2.5, 2.5, 2.5), de = structure(c(4L, 4L, 4L, 4L, 4L, 4L,
1L, 1L, 1L, 3L, 3L, 3L, 2L, 2L, 2L, 1L, 1L, 1L, 4L, 4L, 4L, 2L,
2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 1L, 1L, 1L, 3L, 3L, 3L, 2L, 2L,
2L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L,
4L, 4L, 4L, 1L, 1L, 1L, 3L, 3L, 3L, 2L, 2L, 2L, 1L, 1L, 1L, 4L,
4L, 4L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 1L, 1L, 1L, 3L, 3L,
3L, 2L, 2L, 2L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
4L, 4L, 4L, 4L, 1L, 1L, 3L, 3L, 2L, 2L, 1L, 1L, 4L, 4L, 2L, 2L,
3L, 3L, 4L, 4L, 1L, 1L, 3L, 3L, 2L, 2L, 4L, 4L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = c("de1", "de2", "de3", "de4"), class = "factor")), row.names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35",
"36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46",
"47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57",
"58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68",
"69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
"80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90",
"91", "92", "93", "94", "95", "96", "97", "98", "99", "100",
"101", "102", "110", "410", "710", "103", "131", "161", "191",
"221", "251", "281", "311", "341", "371", "401", "431", "461",
"491", "521", "551", "581", "611", "641", "671", "701", "731",
"761", "791", "821", "851", "881", "911", "941", "971", "1001"
), .Names = c("name", "Contr.finish", "variable", "value", "bar",
"de"), class = "data.frame")
dfr<-structure(list(name = structure(c(2L, 4L, 3L, 1L), .Label = c("10004/07",
"10012/06", "458/07", "512/12"), class = "factor"), text = c("Region 1",
"Region 2", "Region 3", "Region 4"), name0 = c(0, 6.5, 9.5, 12.5
)), .Names = c("name", "text", "name0"), row.names = c(NA, -4L
), class = "data.frame")
library(ggplot2)
library(scales)
library(ggthemes)
ggplot(mdfr, aes(as.POSIXct(as.Date(value, "%Y-%m-%d")), name, colour = Contr.finish)) +
geom_line(aes(size=bar)) +
guides(colour = guide_legend(override.aes = list(size=5)), size="none", fill="none") +
geom_line(size=2.0) +
xlab("") + ylab("") +
theme_stata() +
geom_hline(data=dfr, aes(yintercept = name0), color = "#4d4d4d", size=0.8) + #
scale_fill_brewer(palette="Dark2") +
scale_x_datetime(breaks = date_breaks("1 year"),labels = abbreviate) +
scale_colour_manual(values=c("Initial" = "#67bf5c", "Current" = "#1f77b4",
"Forecast" = "#ff9e4a", "Cost" = "#c10534")) +
theme(legend.position = "bottom",
axis.text.y=element_text(angle=0)
)
You can use geom_rect() and there set xmin= and xmax= to minimal and maximal values of your dates or some other values outside the limits. For the ymin= and ymax= used name values converted to numeric (they have to factors in your dataframe) and then -0.5 and +0.5 (as for each discrete value there is place of 1 around it). Added expand=c(0,0) to scale_x_datetime() to remove white areas.
+ geom_rect(aes(xmin=min(as.POSIXct(as.Date(value, "%Y-%m-%d"))),
xmax=max(as.POSIXct(as.Date(value, "%Y-%m-%d"))),
ymin=as.numeric(name)-0.5,ymax=as.numeric(name)+0.5,
fill=de),alpha=0.05,linetype=0)
I have a dataframe called dataw that I'm trying to plot into dual facet wrapped boxplots.
dataw <- structure(list(base = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L,
4L), .Label = c("A", "C", "G", "T"), class = "factor"), pos = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L), values = c(13, 22, 16, 1, 1.709,
2.121, 2.061, 1, 5, 6, 1, 0.856, 1.116, 1.207, 76, 45, 5, 15,
8.558, 5.44, 1.147, 10, 7, 40, 5, 1.547, 1.174, 4.777, 7, 0,
1, 8, 1.322, 0.728, 0.83, 4, 2, 0, 0, 1.098, 0.96, 0.63, 13,
22, 16, 1, 1.709, 2.121, 2.061, 3, 6, 7, 11, 0.952, 1.474, 1.45,
13, 22, 16, 1, 1.709, 2.121, 2.061, 3, 8, 15, 2, 1.014, 1.583,
2.289, 10, 3, 8, 2, 1.504, 1.03, 1.244, 4, 1, 0, 1, 1.066, 0.862,
0.689, 2, 0, 0, 1, 0.919, 0.723, 0.479, 7, 8, 0, 0, 1.299, 1.236,
0.779, 13, 22, 16, 1, 1.709, 2.121, 2.061, 45, 38, 41, 1, 2.817,
2.264, 2.398, 3, 0, 1, 14, 0.973, 0.641, 0.846, 13, 22, 16, 1,
1.709, 2.121, 2.061, 7, 0, 0, 1, 1.37, 0.436, 0.706, 0, 5, 5,
1, 0.597, 1.113, 1.079, 3, 1, 4, 8, 0.992, 0.84, 1.07, 17, 7,
18, 1, 2.4, 1.315, 1.948, 21, 8, 50, 12, 2.412, 1.254, 3.857,
13, 22, 16, 1, 1.709, 2.121, 2.061), type = structure(c(2L, 2L,
2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 1L, 1L, 1L), .Label = c("ipdRatio", "score"), class = "factor")), .Names = c("base",
"pos", "values", "type"), row.names = c("1", "2", "3", "3942",
"3943", "3944", "3945", "11", "21", "31", "63", "64", "65", "66",
"12", "22", "32", "2953", "2954", "2955", "2956", "13", "23",
"33", "2461", "2462", "2463", "2464", "14", "24", "34", "7493",
"7494", "7495", "7496", "111", "212", "311", "4874", "4875",
"4876", "4877", "121", "221", "321", "9356", "9357", "9358",
"9359", "131", "231", "331", "9221", "9222", "9223", "9224",
"15", "25", "35", "93561", "93571", "93581", "93591", "112",
"213", "312", "1579", "1580", "1581", "1582", "122", "222", "322",
"1782", "1783", "1784", "1785", "132", "232", "332", "3398",
"3399", "3400", "3401", "16", "26", "36", "2257", "2258", "2259",
"2260", "113", "214", "313", "1027", "1028", "1029", "1030",
"123", "223", "323", "8654", "8655", "8656", "8657", "133", "233",
"333", "702", "703", "704", "705", "17", "27", "37", "8123",
"8124", "8125", "8126", "114", "215", "314", "93562", "93572",
"93582", "93592", "124", "224", "324", "3700", "3701", "3702",
"3703", "134", "234", "334", "8233", "8234", "8235", "8236",
"18", "28", "38", "1542", "1543", "1544", "1545", "115", "216",
"315", "533", "534", "535", "536", "125", "225", "325", "208",
"209", "210", "211", "135", "235", "335", "93563", "93573", "93583",
"93593"), class = "data.frame")
I'm plotting it like this:
prettify <- theme(panel.background = element_rect(fill = NA,color="gray"),
panel.grid.major.y = element_blank(),
panel.grid.major.x = element_line(size=.1, color="black",linetype="dotted"),
panel.grid.minor.y = element_blank(),
panel.grid.minor.x = element_line(size=.1, color="black"),
legend.position="bottom")
ggplot(dataw,aes(x = base, y = values, color = type, group = type)) +
geom_boxplot() +
facet_wrap(type ~ pos, scales="free", nrow = 2) +
theme_gray() %+replace% prettify
But I keep getting only one boxplot in each plot square like so, when in fact I want 4 boxplots for each square:
Does anyone see what I am doing wrong here? Thanks!
So, I have created a list (and a single column matrix) that contains 256 nested lists. What I would like to do, is to convert each of the 256 lists into a single dataframe of 16 columns and then write.table it. Although each list contains the same number of columns (16), the number of rows for each list varies. I have tried to use unlist unsuccessfully because the changing row counts. I can subset each list individually, so I know there's an easier way to do the whole list.
I'm pretty new to R, so I apologize for asking what may be a naive novice question. I searched through a lot of topics the last couple days and didn't see anything that seemed to match my problem. for loop seems like it might be unnecessary and I wasn't sure if lapply was the correct route, either.
UPDATE: dput of first list:
list(structure(list(structure(c(2L, 11L, 15L, 8L, 7L, 3L, 6L, 10L,
1L, 1L, 18L, 13L, 14L, 19L, 16L, 17L, 4L, 5L, 9L, 12L), .Label = c("",
"Aaron Rodgers", "Andrew Quarless", "Derrick Coleman", "Doug Baldwin",
"DuJuan Harris", "Eddie Lacy", "James Starks", "Jermaine Kearse",
"John Kuhn", "Jordy Nelson", "Luke Willson", "Marshawn Lynch", "Percy
Harvin", "Randall Cobb", "Ricardo Lockette", "Robert Turbin",
"Russell Wilson", "Zach Miller"), class = "factor"), Tm =
structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 4L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L), .Label = c("GNB", "Passing", "SEA", "Tm"),
class = "factor"), Cmp = structure(c(3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 4L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("", "19",
"23", "Cmp", "Rushing"), class = "factor"), Att = structure(c(3L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 4L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), .Label = c("", "28", "33", "Att", "Receiving"
), class = "factor"), Yds = structure(c(2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, NA, 4L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), .Label = c("", "189", "191", "Yds"), class = "factor"),
TD = structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, NA, 4L,
3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("", "1",
"2", "TD"), class = "factor"), Int = structure(c(3L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, NA, 4L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = c("", "0", "1", "Int"), class = "factor"),
Lng = structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, NA, 4L,
3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("", "23",
"33", "Lng"), class = "factor"), Att = structure(c(1L, 1L,
1L, 7L, 3L, 1L, 2L, 2L, NA, 8L, 7L, 4L, 5L, 1L, 1L, 6L, 1L,
1L, 1L, 1L), .Label = c("", "1", "12", "20", "4", "6", "7",
"Att"), class = "factor"), Yds = structure(c(1L, 1L, 1L,
7L, 6L, 1L, 9L, 3L, NA, 10L, 5L, 2L, 8L, 1L, 1L, 4L, 1L,
1L, 1L, 1L), .Label = c("", "110", "2", "27", "29", "34",
"37", "41", "7", "Yds"), class = "factor"), TD = structure(c(1L,
1L, 1L, 2L, 2L, 1L, 2L, 3L, NA, 5L, 2L, 4L, 2L, 1L, 1L, 2L,
1L, 1L, 1L, 1L), .Label = c("", "0", "1", "2", "TD"), class = "factor"),
Lng = structure(c(1L, 1L, 1L, 2L, 4L, 1L, 8L, 6L, NA, 9L,
3L, 7L, 5L, 1L, 1L, 8L, 1L, 1L, 1L, 1L), .Label = c("", "12",
"13", "15", "16", "2", "21", "7", "Lng"), class = "factor"),
Rec = structure(c(1L, 7L, 5L, 3L, 4L, 4L, 1L, 1L, NA, 8L,
1L, 2L, 6L, 4L, 3L, 1L, 2L, 4L, 2L, 2L), .Label = c("", "1",
"2", "3", "6", "7", "9", "Rec"), class = "factor"), Yds = structure(c(1L,
12L, 9L, 3L, 3L, 6L, 1L, 1L, NA, 13L, 1L, 4L, 10L, 8L, 7L,
1L, 5L, 4L, 11L, 2L), .Label = c("", "1", "11", "14", "15",
"26", "38", "42", "58", "59", "8", "83", "Yds"), class = "factor"),
TD = structure(c(1L, 2L, 3L, 2L, 2L, 2L, 1L, 1L, NA, 4L,
1L, 2L, 2L, 2L, 3L, 1L, 3L, 2L, 2L, 2L), .Label = c("", "0",
"1", "TD"), class = "factor"), Lng = structure(c(1L, 7L,
9L, 3L, 4L, 8L, 1L, 1L, NA, 14L, 1L, 5L, 11L, 10L, 11L, 1L,
6L, 12L, 13L, 2L), .Label = c("", "1", "11", "12", "14",
"15", "16", "18", "23", "24", "33", "6", "8", "Lng"), class = "factor")), .Names = c("", "Tm", "Cmp", "Att", "Yds", "TD", "Int",
"Lng", "Att", "Yds", "TD", "Lng", "Rec", "Yds", "TD", "Lng"),
row.names = c(NA, -20L ), class = "data.frame"))
So, each observation in my list is like this above and I want to convert all of the lists into their 16 column(Now that I think about it, it's 17 columns, one is just unnamed) dataframe layout and stack all the rows together in one place that I can then write.table
Let's call your list l where l[[1]] is what you have dput above.
Two easy ways from base R and from data.table
do.call("rbind", l)
data.table::rbindlist(l)
This assumes that the columns match in each list element. Your example doesn't confirm this, although you state it.