Plots do not render properly in markdown - r-markdown
I have problem plotting side by side plots in markdown, instead, they are one after each other.
{r fn, fig.show = "hold", warning=FALSE, message=FALSE,fig.width=5, fig.height=5, fig.path='figures/', dev=c('png', 'pdf')}
And this is the code to produce plots, sorry about the length. I have a few more plots in the document and all of them work the way I want them to work (using par or just markdown for stacking them together). I suspect it has something to do with the plotting code.
list(structure(list(data = structure(list(model = c("90_10_12_rain",
"90_10_12_rain", "90_10_12_rain", "90_10_12_rain", "90_10_12_rain",
"90_10_12_rain", "90_10_12_rain", "90_10_12_rain", "90_10_12_rain",
"90_10_12_rain", "90_10_12_rain", "90_10_12_rain", "90_10_12_rain",
"90_10_12_rain", "90_10_12_rain", "90_10_12_rain", "90_10_12_rain",
"90_10_12_rain", "90_10_12_rain", "90_10_12_rain"), sens = c(0,
0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4,
0.5, 0.6, 0.6, 0.7, 0.8, 1), one_min_spec = c(0, 0.0412371134020618,
0.0412371134020618, 0.0412371134020618, 0.0824742268041238, 0.0824742268041238,
0.0824742268041238, 0.0824742268041238, 0.103092783505155, 0.103092783505155,
0.123711340206186, 0.144329896907217, 0.164948453608247, 0.175257731958763,
0.195876288659794, 0.237113402061856, 0.283505154639175, 0.319587628865979,
0.373711340206186, 1), cut_point = c(NA, 18L, 17L, 16L, 15L,
14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L,
NA)), row.names = c(1L, 11834L, 11148L, 10462L, 9776L, 9090L,
8404L, 7718L, 7032L, 6346L, 5660L, 4974L, 4288L, 3602L, 2916L,
2230L, 1544L, 858L, 172L, 20L), class = "data.frame"), layers = list(
<environment>, <environment>, <environment>, <environment>,
<environment>), scales = <environment>, mapping = structure(list(
x = ~one_min_spec, y = ~sens, label = ~cut_point), class = "uneval"),
theme = structure(list(line = structure(list(colour = "black",
size = 0.5, linetype = 1, lineend = "butt", arrow = FALSE,
inherit.blank = TRUE), class = c("element_line", "element"
)), rect = structure(list(fill = "white", colour = "black",
size = 0.5, linetype = 1, inherit.blank = TRUE), class = c("element_rect",
"element")), text = structure(list(family = "", face = "plain",
colour = "black", size = 14, hjust = 0.5, vjust = 0.5,
angle = 0, lineheight = 0.9, margin = structure(c(0,
0, 0, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = FALSE, inherit.blank = FALSE), class = c("element_text",
"element")), axis.title.x = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 1, angle = NULL, lineheight = NULL, margin = structure(c(2.75,
0, 0, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.title.x.top = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 0, angle = NULL, lineheight = NULL, margin = structure(c(0,
0, 2.75, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.title.y = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 1, angle = 90, lineheight = NULL, margin = structure(c(0,
2.75, 0, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.title.y.right = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 0, angle = -90, lineheight = NULL, margin = structure(c(0,
0, 0, 2.75), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.text = structure(list(family = NULL, face = NULL,
colour = "grey30", size = structure(0.8, class = "rel"),
hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL,
margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.text.x = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 1, angle = NULL, lineheight = NULL, margin = structure(c(2.2,
0, 0, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.text.x.top = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 0, angle = NULL, lineheight = NULL, margin = structure(c(0,
0, 2.2, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.text.y = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = 1, vjust = NULL,
angle = NULL, lineheight = NULL, margin = structure(c(0,
2.2, 0, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.text.y.right = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = 0, vjust = NULL,
angle = NULL, lineheight = NULL, margin = structure(c(0,
0, 0, 2.2), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.ticks = structure(list(colour = "grey20",
size = NULL, linetype = NULL, lineend = NULL, arrow = FALSE,
inherit.blank = TRUE), class = c("element_line", "element"
)), axis.ticks.length = structure(2.75, class = "unit", valid.unit = 8L, unit = "pt"),
axis.line = structure(list(), class = c("element_blank",
"element")), axis.line.x = NULL, axis.line.y = NULL,
legend.background = structure(list(fill = NULL, colour = NA,
size = NULL, linetype = NULL, inherit.blank = TRUE), class = c("element_rect",
"element")), legend.margin = structure(c(5.5, 5.5, 5.5,
5.5), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
legend.spacing = structure(11, class = "unit", valid.unit = 8L, unit = "pt"),
legend.spacing.x = NULL, legend.spacing.y = NULL, legend.key = structure(list(
fill = "white", colour = NA, size = NULL, linetype = NULL,
inherit.blank = TRUE), class = c("element_rect",
"element")), legend.key.size = structure(1.2, class = "unit", valid.unit = 3L, unit = "lines"),
legend.key.height = NULL, legend.key.width = NULL, legend.text = structure(list(
family = NULL, face = NULL, colour = NULL, size = structure(0.8, class = "rel"),
hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL,
margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), legend.text.align = NULL, legend.title = structure(list(
family = NULL, face = NULL, colour = NULL, size = NULL,
hjust = 0, vjust = NULL, angle = NULL, lineheight = NULL,
margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), legend.title.align = NULL, legend.position = "right",
legend.direction = NULL, legend.justification = "center",
legend.box = NULL, legend.box.margin = structure(c(0,
0, 0, 0), class = c("margin", "unit"), valid.unit = 1L, unit = "cm"),
legend.box.background = structure(list(), class = c("element_blank",
"element")), legend.box.spacing = structure(11, class = "unit", valid.unit = 8L, unit = "pt"),
panel.background = structure(list(fill = "white", colour = NA,
size = NULL, linetype = NULL, inherit.blank = TRUE), class = c("element_rect",
"element")), panel.border = structure(list(fill = NA,
colour = "grey20", size = NULL, linetype = NULL,
inherit.blank = TRUE), class = c("element_rect",
"element")), panel.spacing = structure(5.5, class = "unit", valid.unit = 8L, unit = "pt"),
panel.spacing.x = NULL, panel.spacing.y = NULL, panel.grid = structure(list(
colour = "grey92", size = NULL, linetype = NULL,
lineend = NULL, arrow = FALSE, inherit.blank = TRUE), class = c("element_line",
"element")), panel.grid.major = structure(list(), class = c("element_blank",
"element")), panel.grid.minor = structure(list(), class = c("element_blank",
"element")), panel.ontop = FALSE, plot.background = structure(list(
fill = NULL, colour = "white", size = NULL, linetype = NULL,
inherit.blank = TRUE), class = c("element_rect",
"element")), plot.title = structure(list(family = NULL,
face = NULL, colour = NULL, size = structure(1.2, class = "rel"),
hjust = 0, vjust = 1, angle = NULL, lineheight = NULL,
margin = structure(c(0, 0, 5.5, 0), class = c("margin",
"unit"), valid.unit = 8L, unit = "pt"), debug = NULL,
inherit.blank = TRUE), class = c("element_text",
"element")), plot.subtitle = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = 0,
vjust = 1, angle = NULL, lineheight = NULL, margin = structure(c(0,
0, 5.5, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), plot.caption = structure(list(family = NULL,
face = NULL, colour = NULL, size = structure(0.8, class = "rel"),
hjust = 1, vjust = 1, angle = NULL, lineheight = NULL,
margin = structure(c(5.5, 0, 0, 0), class = c("margin",
"unit"), valid.unit = 8L, unit = "pt"), debug = NULL,
inherit.blank = TRUE), class = c("element_text",
"element")), plot.tag = structure(list(family = NULL,
face = NULL, colour = NULL, size = structure(1.2, class = "rel"),
hjust = 0.5, vjust = 0.5, angle = NULL, lineheight = NULL,
margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), plot.tag.position = "topleft", plot.margin = structure(c(5.5,
5.5, 5.5, 5.5), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
strip.background = structure(list(fill = "grey85", colour = "grey20",
size = NULL, linetype = NULL, inherit.blank = TRUE), class = c("element_rect",
"element")), strip.placement = "inside", strip.text = structure(list(
family = NULL, face = NULL, colour = "grey10", size = structure(0.8, class = "rel"),
hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL,
margin = structure(c(4.4, 4.4, 4.4, 4.4), class = c("margin",
"unit"), valid.unit = 8L, unit = "pt"), debug = NULL,
inherit.blank = TRUE), class = c("element_text",
"element")), strip.text.x = NULL, strip.text.y = structure(list(
family = NULL, face = NULL, colour = NULL, size = NULL,
hjust = NULL, vjust = NULL, angle = -90, lineheight = NULL,
margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), strip.switch.pad.grid = structure(2.75, class = "unit", valid.unit = 8L, unit = "pt"),
strip.switch.pad.wrap = structure(2.75, class = "unit", valid.unit = 8L, unit = "pt")), class = c("theme",
"gg"), complete = TRUE, validate = TRUE), coordinates = <environment>,
facet = <environment>, plot_env = <environment>, labels = list(
title = "a) ROC for Tt = 10°C;RHt = 90%; \nSDt = 12 hours; and LW = rain and RH>90%.",
x = "one_min_spec", y = "sens", label = "cut_point",
intercept = "intercept", slope = "slope")), class = c("gg",
"ggplot")), structure(list(data = structure(list(model = c("88_10_10_rainrh",
"88_10_10_rainrh", "88_10_10_rainrh", "88_10_10_rainrh", "88_10_10_rainrh",
"88_10_10_rainrh", "88_10_10_rainrh", "88_10_10_rainrh", "88_10_10_rainrh",
"88_10_10_rainrh", "88_10_10_rainrh", "88_10_10_rainrh", "88_10_10_rainrh",
"88_10_10_rainrh", "88_10_10_rainrh", "88_10_10_rainrh", "88_10_10_rainrh",
"88_10_10_rainrh", "88_10_10_rainrh", "88_10_10_rainrh"), sens = c(0,
0.6, 0.6, 0.6, 0.6, 0.6, 0.7, 0.7, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.9, 1, 1, 1, 1), one_min_spec = c(0, 0.195876288659794,
0.195876288659794, 0.195876288659794, 0.195876288659794, 0.206185567010309,
0.22680412371134, 0.22680412371134, 0.247422680412371, 0.268041237113402,
0.268041237113402, 0.306701030927835, 0.324742268041237, 0.358247422680412,
0.394329896907217, 0.430412371134021, 0.551546391752577, 0.685567010309278,
0.765463917525773, 1), cut_point = c(NA, 18L, 17L, 16L, 15L,
14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L,
NA)), row.names = c(1L, 12277L, 11591L, 10905L, 10219L, 9533L,
8847L, 8161L, 7475L, 6789L, 6103L, 5417L, 4731L, 4045L, 3359L,
2673L, 1987L, 1301L, 615L, 20L), class = "data.frame"), layers = list(
<environment>, <environment>, <environment>, <environment>,
<environment>), scales = <environment>, mapping = structure(list(
x = ~one_min_spec, y = ~sens, label = ~cut_point), class = "uneval"),
theme = structure(list(line = structure(list(colour = "black",
size = 0.5, linetype = 1, lineend = "butt", arrow = FALSE,
inherit.blank = TRUE), class = c("element_line", "element"
)), rect = structure(list(fill = "white", colour = "black",
size = 0.5, linetype = 1, inherit.blank = TRUE), class = c("element_rect",
"element")), text = structure(list(family = "", face = "plain",
colour = "black", size = 14, hjust = 0.5, vjust = 0.5,
angle = 0, lineheight = 0.9, margin = structure(c(0,
0, 0, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = FALSE, inherit.blank = FALSE), class = c("element_text",
"element")), axis.title.x = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 1, angle = NULL, lineheight = NULL, margin = structure(c(2.75,
0, 0, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.title.x.top = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 0, angle = NULL, lineheight = NULL, margin = structure(c(0,
0, 2.75, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.title.y = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 1, angle = 90, lineheight = NULL, margin = structure(c(0,
2.75, 0, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.title.y.right = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 0, angle = -90, lineheight = NULL, margin = structure(c(0,
0, 0, 2.75), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.text = structure(list(family = NULL, face = NULL,
colour = "grey30", size = structure(0.8, class = "rel"),
hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL,
margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.text.x = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 1, angle = NULL, lineheight = NULL, margin = structure(c(2.2,
0, 0, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.text.x.top = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = NULL,
vjust = 0, angle = NULL, lineheight = NULL, margin = structure(c(0,
0, 2.2, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.text.y = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = 1, vjust = NULL,
angle = NULL, lineheight = NULL, margin = structure(c(0,
2.2, 0, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.text.y.right = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = 0, vjust = NULL,
angle = NULL, lineheight = NULL, margin = structure(c(0,
0, 0, 2.2), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), axis.ticks = structure(list(colour = "grey20",
size = NULL, linetype = NULL, lineend = NULL, arrow = FALSE,
inherit.blank = TRUE), class = c("element_line", "element"
)), axis.ticks.length = structure(2.75, class = "unit", valid.unit = 8L, unit = "pt"),
axis.line = structure(list(), class = c("element_blank",
"element")), axis.line.x = NULL, axis.line.y = NULL,
legend.background = structure(list(fill = NULL, colour = NA,
size = NULL, linetype = NULL, inherit.blank = TRUE), class = c("element_rect",
"element")), legend.margin = structure(c(5.5, 5.5, 5.5,
5.5), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
legend.spacing = structure(11, class = "unit", valid.unit = 8L, unit = "pt"),
legend.spacing.x = NULL, legend.spacing.y = NULL, legend.key = structure(list(
fill = "white", colour = NA, size = NULL, linetype = NULL,
inherit.blank = TRUE), class = c("element_rect",
"element")), legend.key.size = structure(1.2, class = "unit", valid.unit = 3L, unit = "lines"),
legend.key.height = NULL, legend.key.width = NULL, legend.text = structure(list(
family = NULL, face = NULL, colour = NULL, size = structure(0.8, class = "rel"),
hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL,
margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), legend.text.align = NULL, legend.title = structure(list(
family = NULL, face = NULL, colour = NULL, size = NULL,
hjust = 0, vjust = NULL, angle = NULL, lineheight = NULL,
margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), legend.title.align = NULL, legend.position = "right",
legend.direction = NULL, legend.justification = "center",
legend.box = NULL, legend.box.margin = structure(c(0,
0, 0, 0), class = c("margin", "unit"), valid.unit = 1L, unit = "cm"),
legend.box.background = structure(list(), class = c("element_blank",
"element")), legend.box.spacing = structure(11, class = "unit", valid.unit = 8L, unit = "pt"),
panel.background = structure(list(fill = "white", colour = NA,
size = NULL, linetype = NULL, inherit.blank = TRUE), class = c("element_rect",
"element")), panel.border = structure(list(fill = NA,
colour = "grey20", size = NULL, linetype = NULL,
inherit.blank = TRUE), class = c("element_rect",
"element")), panel.spacing = structure(5.5, class = "unit", valid.unit = 8L, unit = "pt"),
panel.spacing.x = NULL, panel.spacing.y = NULL, panel.grid = structure(list(
colour = "grey92", size = NULL, linetype = NULL,
lineend = NULL, arrow = FALSE, inherit.blank = TRUE), class = c("element_line",
"element")), panel.grid.major = structure(list(), class = c("element_blank",
"element")), panel.grid.minor = structure(list(), class = c("element_blank",
"element")), panel.ontop = FALSE, plot.background = structure(list(
fill = NULL, colour = "white", size = NULL, linetype = NULL,
inherit.blank = TRUE), class = c("element_rect",
"element")), plot.title = structure(list(family = NULL,
face = NULL, colour = NULL, size = structure(1.2, class = "rel"),
hjust = 0, vjust = 1, angle = NULL, lineheight = NULL,
margin = structure(c(0, 0, 5.5, 0), class = c("margin",
"unit"), valid.unit = 8L, unit = "pt"), debug = NULL,
inherit.blank = TRUE), class = c("element_text",
"element")), plot.subtitle = structure(list(family = NULL,
face = NULL, colour = NULL, size = NULL, hjust = 0,
vjust = 1, angle = NULL, lineheight = NULL, margin = structure(c(0,
0, 5.5, 0), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), plot.caption = structure(list(family = NULL,
face = NULL, colour = NULL, size = structure(0.8, class = "rel"),
hjust = 1, vjust = 1, angle = NULL, lineheight = NULL,
margin = structure(c(5.5, 0, 0, 0), class = c("margin",
"unit"), valid.unit = 8L, unit = "pt"), debug = NULL,
inherit.blank = TRUE), class = c("element_text",
"element")), plot.tag = structure(list(family = NULL,
face = NULL, colour = NULL, size = structure(1.2, class = "rel"),
hjust = 0.5, vjust = 0.5, angle = NULL, lineheight = NULL,
margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), plot.tag.position = "topleft", plot.margin = structure(c(5.5,
5.5, 5.5, 5.5), class = c("margin", "unit"), valid.unit = 8L, unit = "pt"),
strip.background = structure(list(fill = "grey85", colour = "grey20",
size = NULL, linetype = NULL, inherit.blank = TRUE), class = c("element_rect",
"element")), strip.placement = "inside", strip.text = structure(list(
family = NULL, face = NULL, colour = "grey10", size = structure(0.8, class = "rel"),
hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL,
margin = structure(c(4.4, 4.4, 4.4, 4.4), class = c("margin",
"unit"), valid.unit = 8L, unit = "pt"), debug = NULL,
inherit.blank = TRUE), class = c("element_text",
"element")), strip.text.x = NULL, strip.text.y = structure(list(
family = NULL, face = NULL, colour = NULL, size = NULL,
hjust = NULL, vjust = NULL, angle = -90, lineheight = NULL,
margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text",
"element")), strip.switch.pad.grid = structure(2.75, class = "unit", valid.unit = 8L, unit = "pt"),
strip.switch.pad.wrap = structure(2.75, class = "unit", valid.unit = 8L, unit = "pt")), class = c("theme",
"gg"), complete = TRUE, validate = TRUE), coordinates = <environment>,
facet = <environment>, plot_env = <environment>, labels = list(
title = "b) ROC for Tt = 10°C;RHt = 88%; \nSDt = 10 hours; and LW = rain and RH>90%.",
x = "one_min_spec", y = "sens", label = "cut_point",
intercept = "intercept", slope = "slope")), class = c("gg",
"ggplot")))
I wasn't able to use the code you posted. Would using the plot_grid function from the cowplot package be a potential solution?
You can easily generate figures with plots side by side using plot_grid. For example,
plot_grid(p1,p2,nrow=1,labels='auto')
Also, you may try editing your YAML header to include the following:
header-includes:
- \usepackage{float}
- \floatplacement{figure}{H}`
This will insure that figures are inserted where the code that calls them in the document. From bthorne, here.
Related
How to extract exercises names from a nest list of exams from r `exams`?
I created 8 exams using the r exams package (each with the corresponding *.rds file). Each exam has the same 8 items (in a different order). All exams' *.rds were merged into a single list. As follows: exams_list <- list(`00001` = list(exercise1 = list(question = c("\\emph{(2 \\myPoints)}", "Q1"), questionlist = c("A1", "A2","A3", "A4", "A5"), solution = NULL, solutionlist = NULL, metainfo = list(file = "stat1_en_descriptive_stat_34", markup = "latex", type = "schoice", name = "stat1_en_descriptive_stat_34", title = NULL, section = NULL, version = NULL, solution = c(FALSE, FALSE, FALSE, TRUE, FALSE), clozetype = NULL, points = 2, time = NULL, shuffle = 5, length = 5L, string = "stat1_en_descriptive_stat_34: b", maxchars = NULL, abstention = NULL, stringtype = NULL, seed = 40283L), supplements = structure(character(0), names = character(0), dir = "/tmp/RtmpH83QPG/file808555d833f/exam1/exercise1")), exercise2 = list(question = c("\\emph{(2 \\myPoints)}", "Q2", "", "\\hfill\\break", "\\includegraphics[width=0.55\\textwidth,height=\\textheight]{stat1_descriptive_stat_10.png}" ), questionlist = c("A1", "A2","A3", "A4", "A5" ), solution = NULL, solutionlist = NULL, metainfo = list( file = "stat1_en_descriptive_stat_10", markup = "latex", type = "schoice", name = "stat1_en_descriptive_stat_10", title = NULL, section = NULL, version = NULL, solution = c(FALSE, TRUE, FALSE, FALSE, FALSE), clozetype = NULL, points = 2, time = NULL, shuffle = 5, length = 5L, string = "stat1_en_descriptive_stat_10: b", maxchars = NULL, abstention = NULL, stringtype = NULL, seed = 23616L), supplements = structure(c(stat1_descriptive_stat_10.png = "/tmp/RtmpH83QPG/file808555d833f/exam1/exercise2/stat1_descriptive_stat_10.png"), dir = "/tmp/RtmpH83QPG/file808555d833f/exam1/exercise2")), exercise3 = list(question = c("\\emph{(2 \\myPoints)}", "Q3" ), questionlist = c("A1", "A2","A3", "A4", "A5"), solution = NULL, solutionlist = NULL, metainfo = list( file = "stat1_en_descriptive_stat_15", markup = "latex", type = "schoice", name = "stat1_en_descriptive_stat_15", title = NULL, section = NULL, version = NULL, solution = c(FALSE, FALSE, FALSE, TRUE, FALSE), clozetype = NULL, points = 2, time = NULL, shuffle = 5, length = 5L, string = "stat1_en_descriptive_stat_15: d", maxchars = NULL, abstention = NULL, stringtype = NULL, seed = 84038L), supplements = structure(character(0), names = character(0), dir = "/tmp/RtmpH83QPG/file808555d833f/exam1/exercise3")), exercise4 = list(question = c("\\emph{(2 \\myPoints)}", "Q4"), questionlist = c("A1", "A2","A3", "A4", "A5"), solution = NULL, solutionlist = NULL, metainfo = list(file = "stat1_en_descriptive_stat_29", markup = "latex", type = "schoice", name = "stat1_en_descriptive_stat_29", title = NULL, section = NULL, version = NULL, solution = c(FALSE, FALSE, FALSE, TRUE, FALSE), clozetype = NULL, points = 2, time = NULL, shuffle = 5, length = 5L, string = "stat1_en_descriptive_stat_29: d", maxchars = NULL, abstention = NULL, stringtype = NULL, seed = 104204L), supplements = structure(character(0), names = character(0), dir = "/tmp/RtmpH83QPG/file808555d833f/exam1/exercise4")), exercise5 = list(question = c("\\emph{(2 \\myPoints)}", "Q5" ), questionlist = c("A1", "A2","A3", "A4", "A5"), solution = NULL, solutionlist = NULL, metainfo = list(file = "stat1_en_prob_8", markup = "latex", type = "schoice", name = "stat1_en_prob_8", title = NULL, section = NULL, version = NULL, solution = c(FALSE, FALSE, TRUE, FALSE, FALSE), clozetype = NULL, points = 2, time = NULL, shuffle = 5, length = 5L, string = "stat1_en_prob_8: c", maxchars = NULL, abstention = NULL, stringtype = NULL, seed = 99878L), supplements = structure(character(0), names = character(0), dir = "/tmp/RtmpH83QPG/file808555d833f/exam1/exercise5"))), `00002` = list(exercise1 = list(question = c("\\emph{(2 \\myPoints)}", "Q1"), questionlist = c("A1", "A2","A3", "A4", "A5" ), solution = NULL, solutionlist = NULL, metainfo = list( file = "stat1_en_descriptive_stat_10", markup = "latex", type = "schoice", name = "stat1_en_descriptive_stat_10", title = NULL, section = NULL, version = NULL, solution = c(FALSE, FALSE, TRUE, FALSE, FALSE), clozetype = NULL, points = 2, time = NULL, shuffle = 5, length = 5L, string = "stat1_en_descriptive_stat_10: c", maxchars = NULL, abstention = NULL, stringtype = NULL, seed = 66957L), supplements = structure(c(stat1_descriptive_stat_10.png = "/tmp/RtmpH83QPG/file8087677e29b/exam1/exercise1/stat1_descriptive_stat_10.png"), dir = "/tmp/RtmpH83QPG/file8087677e29b/exam1/exercise1")), exercise2 = list(question = c("\\emph{(2 \\myPoints)}", "Q2"), questionlist = c("A1", "A2","A3", "A4", "A5"), solution = NULL, solutionlist = NULL, metainfo = list(file = "stat1_en_descriptive_stat_34", markup = "latex", type = "schoice", name = "stat1_en_descriptive_stat_34", title = NULL, section = NULL, version = NULL, solution = c(FALSE, FALSE, FALSE, TRUE, FALSE ), clozetype = NULL, points = 2, time = NULL, shuffle = 5, length = 5L, string = "stat1_en_descriptive_stat_34: a", maxchars = NULL, abstention = NULL, stringtype = NULL, seed = 24446L), supplements = structure(character(0), names = character(0), dir = "/tmp/RtmpH83QPG/file8087677e29b/exam1/exercise2")), exercise3 = list(question = c("\\emph{(2 \\myPoints)}", "Q3"), questionlist = c("A1", "A2","A3", "A4", "A5"), solution = NULL, solutionlist = NULL, metainfo = list(file = "stat1_en_descriptive_stat_29", markup = "latex", type = "schoice", name = "stat1_en_descriptive_stat_29", title = NULL, section = NULL, version = NULL, solution = c(FALSE, FALSE, TRUE, FALSE, FALSE ), clozetype = NULL, points = 2, time = NULL, shuffle = 5, length = 5L, string = "stat1_en_descriptive_stat_29: c", maxchars = NULL, abstention = NULL, stringtype = NULL, seed = 42982L), supplements = structure(character(0), names = character(0), dir = "/tmp/RtmpH83QPG/file8087677e29b/exam1/exercise3")), exercise4 = list(question = c("\\emph{(4 \\myPoints)}", "Q4" ), questionlist = c("A1", "A2","A3", "A4", "A5"), solution = NULL, solutionlist = NULL, metainfo = list(file = "stat1_en_prob_8", markup = "latex", type = "schoice", name = "stat1_en_prob_8", title = NULL, section = NULL, version = NULL, solution = c(FALSE, TRUE, FALSE, FALSE, FALSE ), clozetype = NULL, points = 4, time = NULL, shuffle = 5, length = 5L, string = "stat1_en_prob_8: b", maxchars = NULL, abstention = NULL, stringtype = NULL, seed = 80660L), supplements = structure(c(stat1_en_descriptive_stat_20_1.png = "/tmp/RtmpH83QPG/file8087677e29b/exam1/exercise4/stat1_en_prob_8_1.png", stat1_en_descriptive_stat_20_2.png = "/tmp/RtmpH83QPG/file8087677e29b/exam1/exercise4/stat1_en_prob_8_2.png" ), dir = "/tmp/RtmpH83QPG/file8087677e29b/exam1/exercise4")), exercise5 = list(question = c("\\emph{(2 \\myPoints)}", "Q5" ), questionlist = c("A1", "A2","A3", "A4", "A5" ), solution = NULL, solutionlist = NULL, metainfo = list( file = "stat1_en_descriptive_stat_15", markup = "latex", type = "schoice", name = "stat1_en_descriptive_stat_15", title = NULL, section = NULL, version = NULL, solution = c(FALSE, TRUE, FALSE, FALSE, FALSE), clozetype = NULL, points = 2, time = NULL, shuffle = 5, length = 5L, string = "stat1_en_descriptive_stat_15: b", maxchars = NULL, abstention = NULL, stringtype = NULL, seed = 69316L), supplements = structure(character(0), names = character(0), dir = "/tmp/RtmpH83QPG/file8087677e29b/exam1/exercise5")))) I want to make a psychometric analysis of each of the items (per exam). As such, I want to extract the names of the exercises per exam, and use them to merge the answers to all the items adequately. For the first step I need to extract the information from this list as follows: exams_list$`00001`$exercise1$metainfo$name exams_list$`00001`$exercise2$metainfo$name #... exams_list$`00002`$exercise1$metainfo$name exams_list$`00002`$exercise2$metainfo$name I tried to use the purrr package but I was not successful. My goal is to end up with list of vectors; one vector per exame containing the names of the exercises.
You can use a nested for() loop or nested sapply() for this: sapply(exams_list, function(x) sapply(x, function(y) y$metainfo$name)) ## 00001 00002 ## exercise1 "stat1_en_descriptive_stat_34" "stat1_en_descriptive_stat_10" ## exercise2 "stat1_en_descriptive_stat_10" "stat1_en_descriptive_stat_34" ## exercise3 "stat1_en_descriptive_stat_15" "stat1_en_descriptive_stat_29" ## exercise4 "stat1_en_descriptive_stat_29" "stat1_en_prob_8" ## exercise5 "stat1_en_prob_8" "stat1_en_descriptive_stat_15" The outer loop/apply is over the random replications (here 2), yielding the columns of the output. And the inner loop/apply is over the exercises in each replication (here 5), yielding the rows of the output. From the matrix above you can obtain the necessary permutation to a desired order of the exercises, e.g., via match(). For the psychometric analysis I typically use the following workflow (using our own psychotools package). ## read nops evaluation output x <- read.csv2("nops_eval.csv", dec = ".") ## select check columns and set 'not answered' to 'incorrect' x <- as.matrix(x[, grep("^check\\.", names(x))]) x[is.na(x)] <- 0 ## here you would have to apply the permutation and set nice colnames ## declare item-response matrix with itemresp class in psychotools library("psychotools") x <- itemresp(x) plot(x) ## fit basic Rasch model (via CML) and person-item map m <- raschmodel(x) piplot(m) Stacked bar plot of raw frequencies Person-item map for Rasch model For more refined analyses you might also be interested in these presentations: Examining Exams with the psycho* Family of R Packages, Psychoco 2015 Examining Exams Using Rasch Models and Assessment of Measurement Invariance, WU Wien 2016
How to make buttons closer?
i'm trying to make a simple calculator using Tkinter, but the buttons are too far apart. This is my full code: from Tkinter import * root = Tk() root.title("Calculadora") display = Entry(root, font = ("Simplified Arabian Fixed", 30), bg = "black", fg = "white", bd = 30).grid(columnspan = 4) Button7 = Button(root, bd = 10, text= "7", padx = 16, font = ("Simplified Arabian Fixed", 20), bg = "black", fg = "white").grid(column = 0, row = 1) Button8 = Button(root, bd = 10, text = "8", padx = 16, font = ("Simplified Arabian Fixed", 20), bg = "black", fg = "white").grid(column = 1, row = 1) Division = Button(root, bd = 10, text = "/", padx = 16, font = ("Simplified Arabian Fixed", 20), bg = "black", fg = "white").grid(column = 2, row = 1) root.mainloop() This occours Is there a way to fix this?
This effect is because the entry is wider than the three buttons. You can set a smaller width and then let the grid geometry manager expand it to cover the width of the buttons with sticky = 'ew'. Also you might want to set justify = 'right' in the entry or it will look funny. I included some text in the example below: from Tkinter import * root = Tk() root.title("Calculadora") txt = StringVar() # StringVar to hold entry text txt.set('123456') # Set StringVar display = Entry(root, font = ("Simplified Arabian Fixed", 30), bg = "black", fg = "white", bd = 30, textvariable = txt, # Set width and justify for entry + sticky to fill available space width = 1, justify = 'right').grid(columnspan = 4, sticky = 'ew') Button7 = Button(root, bd = 10, text= "7", padx = 16, font = ("Simplified Arabian Fixed", 20), bg = "black", fg = "white").grid(column = 0, row = 1) Button8 = Button(root, bd = 10, text = "8", padx = 16, font = ("Simplified Arabian Fixed", 20), bg = "black", fg = "white").grid(column = 1, row = 1) Division = Button(root, bd = 10, text = "/", padx = 16, font = ("Simplified Arabian Fixed", 20), bg = "black", fg = "white").grid(column = 2, row = 1) root.mainloop()
Use sticky="ew" and adjust padx in every grid(...) for buttons to expand the buttons to fill the grid cell. Also you assigned the result of grid(...) to all button variables which always be None. So separate the grid(...) function from the creation function, for example: Button7 = Button(root, bd=10, text="7", padx=16, font=("Simplified Arabian Fixed", 20), bg="black", fg="white") Button7.grid(row=1, column=0, sticky="ew", padx=2)
How to divide container into different sets of columns in tkinter GUI?
I am trying to make a GUI in tkinter. So far I have reached this level. The problem is, I am not able to centre the 4 buttons at the bottom, one of them is going out of the assigned width. This is because while making a top frame, I have assigned columnspan to be 3. If I make it 4 then the centring of the middle part goes off. import Tkinter as tk root = tk.Tk() root.title('Steady State Data Processing') root.geometry('{}x{}'.format(900, 500)) topFrame = tk.Frame(root, bg = 'lavender', width = 900, height=100, relief = 'raised') # , padx = 100, pady=100 topFrame.grid(row = 0, column = 0, columnspan = 3, sticky="w") labelCps = tk.Label(root, text='Cps', width = 0, height = 0, padx = 10, pady = 10) labelIgn = tk.Label(root, text='Ign', width = 0, height = 0, padx = 10, pady = 10) labelInj = tk.Label(root, text='Inj', width = 0, height = 0, padx = 10, pady = 10) labelCps.grid(row = 1, column = 0, sticky='we') labelIgn.grid(row = 1, column = 1, sticky='we') labelInj.grid(row = 1, column = 2, sticky='we') cpsFrame = tk.Frame(root, width = 300, height = 100, relief = 'raised') # , padx = 100, pady=100 cpsFrame.grid(row = 2, column = 0, sticky="nsew") ignFrame = tk.Frame(root, width = 300, height = 100, relief = 'raised') # , padx = 100, pady=100 ignFrame.grid(row = 2, column = 1, sticky="nsew") injFrame = tk.Frame(root, width = 300, height = 100, relief = 'raised') # , padx = 100, pady=100 injFrame.grid(row = 2, column = 2, sticky="nsew") labelAdv = tk.Label(cpsFrame, anchor = 'center', text='Cps adv threshold:') labelAdv.grid(row = 0, column = 0, sticky = 'w') entryAdv = tk.Entry(cpsFrame) entryAdv.grid(row = 0, column = 1, sticky = 'e') labelIgn = tk.Label(ignFrame, justify = 'left', text = 'Dwell start threshold:') labelIgn.grid(row = 0, column = 0, sticky = 'w') entryIgn = tk.Entry(ignFrame) entryIgn.grid(row = 0, column = 1) labelIgn = tk.Label(ignFrame, anchor = 'center', text = 'Dwell end threshold:') labelIgn.grid(row = 1, column = 0) entryIgn = tk.Entry(ignFrame) entryIgn.grid(row = 1, column = 1) labelInj = tk.Label(injFrame, anchor = 'center', text = 'Inj start threshold:') labelInj.grid(row = 0, column = 0) entryInj = tk.Entry(injFrame) entryInj.grid(row = 0, column = 1) labelInj = tk.Label(injFrame, anchor = 'center', text = 'Inj end threshold:') labelInj.grid(row = 1, column = 0) entryInj = tk.Entry(injFrame) entryInj.grid(row = 1, column = 1) root.grid_rowconfigure(3, pad = 50) applyButton = tk.Button(root, text = 'Apply', padx = 30, pady = 15) applyButton.grid(row = 3, columnspan = 3) text = ['Plot raw data', 'Plot tooth rpm', 'Plot cycle rpm', 'Plot ign data'] count = 0 for t in text: dataButton = tk.Button(root ,text = t, width = 5, height = 5 ,anchor = 'center', padx = 30, pady = 15) dataButton.grid(row = 4, column = count, sticky = 'news') # dataButton.grid_columnconfigure(count, weight = 2) count = count + 1 root.mainloop()
To center the buttons, they need to be in a frame. Second, to make them fill the space allocated to them by grid, you have to configure the grid columns in the frame to expand. I'm not sure whether you wanted padding between the buttons, but I added some to the grid command. import Tkinter as tk root = tk.Tk() root.title('Steady State Data Processing') root.geometry('{}x{}'.format(900, 500)) topFrame = tk.Frame(root, bg = 'lavender', width = 900, height=100, relief = 'raised') # , padx = 100, pady=100 topFrame.grid(row = 0, column = 0, columnspan = 3, sticky="w") labelCps = tk.Label(root, text='Cps', width = 0, height = 0, padx = 10, pady = 10) labelIgn = tk.Label(root, text='Ign', width = 0, height = 0, padx = 10, pady = 10) labelInj = tk.Label(root, text='Inj', width = 0, height = 0, padx = 10, pady = 10) labelCps.grid(row = 1, column = 0, sticky='we') labelIgn.grid(row = 1, column = 1, sticky='we') labelInj.grid(row = 1, column = 2, sticky='we') cpsFrame = tk.Frame(root, width = 300, height = 100, relief = 'raised') # , padx = 100, pady=100 cpsFrame.grid(row = 2, column = 0, sticky="nsew") ignFrame = tk.Frame(root, width = 300, height = 100, relief = 'raised') # , padx = 100, pady=100 ignFrame.grid(row = 2, column = 1, sticky="nsew") injFrame = tk.Frame(root, width = 300, height = 100, relief = 'raised') # , padx = 100, pady=100 injFrame.grid(row = 2, column = 2, sticky="nsew") labelAdv = tk.Label(cpsFrame, anchor = 'center', text='Cps adv threshold:') labelAdv.grid(row = 0, column = 0, sticky = 'w') entryAdv = tk.Entry(cpsFrame) entryAdv.grid(row = 0, column = 1, sticky = 'e') labelIgn = tk.Label(ignFrame, justify = 'left', text = 'Dwell start threshold:') labelIgn.grid(row = 0, column = 0, sticky = 'w') entryIgn = tk.Entry(ignFrame) entryIgn.grid(row = 0, column = 1) labelIgn = tk.Label(ignFrame, anchor = 'center', text = 'Dwell end threshold:') labelIgn.grid(row = 1, column = 0) entryIgn = tk.Entry(ignFrame) entryIgn.grid(row = 1, column = 1) labelInj = tk.Label(injFrame, anchor = 'center', text = 'Inj start threshold:') labelInj.grid(row = 0, column = 0) entryInj = tk.Entry(injFrame) entryInj.grid(row = 0, column = 1) labelInj = tk.Label(injFrame, anchor = 'center', text = 'Inj end threshold:') labelInj.grid(row = 1, column = 0) entryInj = tk.Entry(injFrame) entryInj.grid(row = 1, column = 1) root.grid_rowconfigure(3, pad = 50) applyButton = tk.Button(root, text = 'Apply', padx = 30, pady = 15) applyButton.grid(row = 3, columnspan = 3) text = ['Plot raw data', 'Plot tooth rpm', 'Plot cycle rpm', 'Plot ign data'] count = 0 # Button frame frame = tk.Frame(root) frame.grid(row=4, column=0, sticky='news', columnspan=4) for t in text: # Expand the column widths as required by the window cavity. frame.grid_columnconfigure(count, weight=1) dataButton = tk.Button(frame ,text = t, width = 5, height = 5 ,anchor = 'center', padx = 30, pady = 15) dataButton.grid(row = 0, column = count, sticky = 'news', padx=30) # dataButton.grid_columnconfigure(count, weight = 2) count = count + 1 root.mainloop()
Prefix column index to column names in list of data frames
I'd like to prefix column numbers to column names in a data frame. What's the best way of doing this? For example, I'd like something like "1_mpg", "2_cyl" in the following table: structure(list(mpg = c(21, 21), cyl = c(6, 6)), .Names = c("mpg", "cyl"), row.names = c("Mazda RX4", "Mazda RX4 Wag"), class = "data.frame") And then how about extending that to a list of data frames? list(structure(list(mpg = c(21, 21), cyl = c(6, 6)), .Names = c("mpg", "cyl"), row.names = c("Mazda RX4", "Mazda RX4 Wag"), class = "data.frame"), structure(list(mpg = c(21, 21), cyl = c(6, 6)), .Names = c("mpg", "cyl"), row.names = c("Mazda RX4", "Mazda RX4 Wag"), class = "data.frame"))
Here's what I ended up using (though I'm guessing there's something more elegant): # sample list of 2 data frames x = list(structure(list(mpg = c(21, 21), cyl = c(6, 6)), .Names = c("mpg", "cyl"), row.names = c("Mazda RX4", "Mazda RX4 Wag"), class = "data.frame"), structure(list(mpg = c(21, 21), cyl = c(6, 6)), .Names = c("mpg", "cyl"), row.names = c("Mazda RX4", "Mazda RX4 Wag"), class = "data.frame")) # create function to append an index to column names newColNames = function(a) { b=lapply(seq_along(colnames(a)), function(i) paste(i,"_",colnames(a)[i],sep="")) colnames(a)=b return(a) } # apply function new_list = lapply(x, function(y) newColNames(y))
Django many to many filtering optimization
Do you have any idea how to opitimize (time) this query? It is so slow even if wordpress population is around 1000. query: al = Wordpress.objects.all().order_by('?') zaplecza = Wordpress.objects.none() for l in labels.split(","): zaplecza = zaplecza | al.filter(label = l) zaplecza = zaplecza.exclude(wordpress__url = project_name) <--very slow models.py class Wordpress(models.Model): url = models.CharField(max_length = 1000) login = models.CharField(max_length = 1000, default = "admin") password = models.CharField(max_length = 1000, default = "perkoz") label = models.CharField(max_length = 1000) cms = models.CharField(max_length = 1000) class Project(models.Model): url = models.CharField(max_length = 1000) links = models.TextField(blank = True, null = True, verbose_name = "Linki do wpisów") wordpress = models.ManyToManyField(Wordpress, related_name = "wordpress", verbose_name = "Dodane do zaplecz") main_link = models.CharField(max_length = 1000) dir_links = models.TextField(blank = True, null = True, verbose_name="Anchory") blog_links = models.TextField(blank = True, null = True, verbose_name="Lista linków i anchorów z ;;;") category = models.ForeignKey(Category, related_name = "projekt") kategorie = models.CharField(max_length = 1000) labels = models.CharField(max_length = 1000) tagi = models.CharField(max_length = 1000) auto_tekst = models.BooleanField(verbose_name="Auto tekst") arts = models.TextField(blank = True, null = True, verbose_name="Artykuły") title = models.TextField(blank = True, null = True, verbose_name="Tytuł") no = models.IntegerField(blank = True, null = True, verbose_name="Liczba wpisów") last_added = models.DateTimeField(blank = True, null = True, verbose_name="Ostatnio dodane")
You're fetching m2m related objects, so you should use prefetch_related in your query to optimize it. https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.prefetch_related