Connecting points by levels of a variable - r

I have a dataset that I'm using in RStudio, and I have the code ggplot(desktop_2015) + geom_point(aes(Month, CV, color = Day), size = 2.5) in order to get a graph that I need.
I am plotting the variable CV by Month, and for each month there are 7 points along the vertical, each a different color representing a level of the variable Day.
What I am trying to do is connect the points for each day across the months, ie a line connecting each Friday point across the 12 months, and so on for each day of the week. I have attached images of what my dataset looks like in addition to the graph I currently have. TIA!
Here's the dput output of my dataset:
structure(list(Year = 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, 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), .Label = c("2015",
"2016", "2017", "2018", "2019"), class = "factor"), Quarter = structure(c(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, 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), .Label = c("1", "2", "3", "4"), class = "factor"),
Month = 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, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L,
12L, 12L, 12L, 12L), .Label = c("Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), class = "factor"),
Device = 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, 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
), .Label = c("D", "M", "T"), class = "factor"), Day = structure(c(4L,
2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L,
6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L,
7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L,
5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L,
1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L,
3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L), .Label = c("Friday", "Monday",
"Saturday", "Sunday", "Thursday", "Tuesday", "Wednesday"), class = "factor"),
Clicks = c(1479, 1631, 1471, 1382, 1926, 1724, 1928, 1233,
1380, 1164, 1145, 1187, 1082, 1201, 1927, 1825, 1592, 1232,
1225, 1181, 1320, 1437, 1357, 1487, 1769, 1655, 1256, 1318,
1512, 1508, 1358, 1176, 1111, 1364, 1316, 1441, 2131, 1956,
1455, 1431, 1280, 1288, 2106, 2326, 2109, 2474, 2397, 2200,
1721, 2598, 2767, 2112, 2045, 1997, 1771, 2352, 2075, 2441,
2670, 2543, 1973, 1876, 1920, 2206, 2529, 2134, 2000, 2514,
2551, 2758, 3087, 3219, 2314, 2150, 1906, 1997, 2335, 1957,
2272, 2617, 2489, 2199, 1657, 1945), Conversions = c(67,
95, 110, 101, 88, 105, 114, 89, 92, 79, 67, 72, 96, 76, 139,
125, 89, 47, 63, 73, 78, 97, 127, 69, 96, 61, 50, 90, 83,
91, 85, 56, 117, 66, 94, 48, 86, 71, 63, 53, 46, 56, 67,
75, 64, 64, 63, 55, 59, 74, 71, 62, 59, 57, 40, 71, 69, 84,
80, 101, 61, 76, 56, 93, 69, 50, 47, 73, 67, 98, 108, 127,
59, 67, 68, 88, 77, 60, 69, 82, 72, 55, 44, 54), CV = c(9089.21,
7811.24, 13201.19, 11394.8, 12631.15, 12389.61, 11742.6,
10265.62, 12449.76, 9329.68, 8255.08, 9002.71, 13173.41,
6235.05, 15480.72, 17940.65, 13667.19, 5766.98, 7583.03,
6817.59, 6412.43, 10441.66, 23018.46, 9243.69, 10521.5, 15117.06,
5791.93, 7783.52, 8156.31, 9996.18, 12973.64, 6329.24, 20080.53,
6289.64, 10891.91, 7176.93, 10281.64, 10292.1, 10077.85,
9299.89, 5979.86, 6888.64, 6799.56, 13162.34, 10267.85, 10599.65,
8868.4, 7285.48, 8393, 9930.09, 10857.6, 12568.96, 9998.93,
8465.09, 6733.55, 11107.85, 10919.87, 12933.21, 14653.55,
22648.43, 13272.86, 15214.25, 9733.4, 18128.61, 12915.65,
10267.21, 9804.48, 11928.58, 14135.84, 19990.35, 15482.84,
20116.57, 12705.79, 12891.93, 11266.43, 16632.9, 11890.34,
9290.67, 11417.62, 18980.21, 11025.63, 7806.93, 7246.12,
7737.87), `Conv. rate` = c(0.0453, 0.0582, 0.0748, 0.0731,
0.0457, 0.0609, 0.0591, 0.0722, 0.0667, 0.0679, 0.0585, 0.0607,
0.0887, 0.0633, 0.0721, 0.0685, 0.0559, 0.0381, 0.0514, 0.0618,
0.0591, 0.0675, 0.0936, 0.0464, 0.0543, 0.0369, 0.0398, 0.0683,
0.0549, 0.0603, 0.0626, 0.0476, 0.1053, 0.0484, 0.0714, 0.0333,
0.0404, 0.0363, 0.0433, 0.037, 0.0359, 0.0435, 0.0318, 0.0322,
0.0303, 0.0259, 0.0263, 0.025, 0.0343, 0.0285, 0.0257, 0.0294,
0.0289, 0.0285, 0.0226, 0.0302, 0.0333, 0.0344, 0.03, 0.0397,
0.0309, 0.0405, 0.0292, 0.0422, 0.0273, 0.0234, 0.0235, 0.029,
0.0263, 0.0355, 0.035, 0.0395, 0.0255, 0.0312, 0.0357, 0.0441,
0.033, 0.0307, 0.0304, 0.0313, 0.0289, 0.025, 0.0266, 0.0278
), `CV/Click` = c(6.15, 4.79, 8.97, 8.25, 6.56, 7.19, 6.09,
8.33, 9.02, 8.02, 7.21, 7.58, 12.18, 5.19, 8.03, 9.83, 8.58,
4.68, 6.19, 5.77, 4.86, 7.27, 16.96, 6.22, 5.95, 9.13, 4.61,
5.91, 5.39, 6.63, 9.55, 5.38, 18.07, 4.61, 8.28, 4.98, 4.82,
5.26, 6.93, 6.5, 4.67, 5.35, 3.23, 5.66, 4.87, 4.28, 3.7,
3.31, 4.88, 3.82, 3.92, 5.95, 4.89, 4.24, 3.8, 4.72, 5.26,
5.3, 5.49, 8.91, 6.73, 8.11, 5.07, 8.22, 5.11, 4.81, 4.9,
4.74, 5.54, 7.25, 5.02, 6.25, 5.49, 6, 5.91, 8.33, 5.09,
4.75, 5.03, 7.25, 4.43, 3.55, 4.37, 3.98), Impressions = c(86045,
89512, 81503, 81356, 101254, 95972, 100790, 73492, 81709,
71678, 67884, 68429, 61978, 69537, 99440, 99735, 95689, 71773,
71414, 65363, 69422, 77640, 76419, 81980, 97540, 90953, 67780,
68886, 81265, 79079, 70807, 65774, 59298, 72504, 71965, 92817,
132684, 120931, 93380, 89791, 82604, 79651, 121598, 141042,
132627, 167622, 146056, 133295, 103366, 151998, 170043, 142676,
126557, 121835, 121060, 139303, 113975, 127019, 151171, 140981,
110230, 108527, 106218, 123960, 136940, 123136, 120845, 145673,
136340, 144527, 185146, 210133, 157902, 135150, 124981, 132650,
136682, 127909, 156160, 219576, 187283, 143617, 107303, 128768
), Cost = c(1376.23, 1799.57, 1646.93, 1631.22, 2088.67,
1869.83, 1779.56, 1152.91, 1643.25, 1281.38, 1368.1, 1299.16,
1184.99, 1183.82, 1690.38, 2065.43, 1737.26, 1351.85, 1432.21,
1395.46, 1192.53, 1385.88, 1548.41, 1754.96, 2148.9, 2061.52,
1481.82, 1400.12, 1595.65, 1808.54, 1643.06, 1417.31, 1343.52,
1794.69, 1317.59, 1436.56, 2344.1, 2124.41, 1602.12, 1449.17,
1417.73, 1337.39, 1773.49, 2018.75, 1813.7, 2181.56, 2069.48,
1938.4, 1528.46, 1907.15, 2163.95, 1645.47, 1620.2, 1552.78,
1326.68, 1749.51, 1466.75, 1851.91, 1997.14, 1909.85, 1506.9,
1391.86, 1420.54, 1671.03, 1948.89, 1657.35, 1577.12, 1888.6,
1934.2, 2055.61, 2357.6, 2426.16, 1730.51, 1652.82, 1464.03,
1550.73, 1736.98, 1364.01, 1625.97, 1835.38, 1714.8, 1584.55,
1109.67, 1340.77)), row.names = c(2L, 4L, 7L, 12L, 15L, 18L,
19L, 23L, 26L, 28L, 31L, 36L, 38L, 40L, 44L, 47L, 51L, 52L, 57L,
58L, 63L, 64L, 69L, 72L, 74L, 78L, 81L, 82L, 85L, 89L, 92L, 95L,
97L, 100L, 105L, 107L, 111L, 113L, 116L, 119L, 121L, 124L, 127L,
130L, 135L, 136L, 141L, 142L, 147L, 149L, 152L, 154L, 158L, 161L,
163L, 167L, 171L, 174L, 177L, 178L, 181L, 185L, 188L, 191L, 194L,
198L, 201L, 202L, 207L, 208L, 211L, 215L, 218L, 221L, 225L, 228L,
230L, 232L, 236L, 238L, 242L, 246L, 247L, 250L), class = "data.frame")

I think you need to provide both group and color in your aes:
library(ggplot2)
ggplot(df, aes(x = Month, y = CV, color = Day, group = Day))+
geom_point()+
geom_line()

Related

How can I apply restrictions and limited accessibility to inputs based on values from other inputs in Shiny?

I am completely new to shiny, and I am trying to create a quite simple app as part of learning it.
Questions:
(1) how can I apply a restriction on the sliderInput("n.sygdom" ...)? The intention is that the user receives an error if one chooses a value greater than the one set in sliderInput("n.fjernet" ...)?
(2) how can I make the radioButtons("ecs" ...) and radioButtons("contra.pos" ...) accessible only if sliderInput("n.sygdom" ...) ≥ 1? Preferable, if sliderInput("n.sygdom" ...)==0, then the radioButtons should be "removed" from the shinyapp
The shinyapp works by calculating a nomogram-score, which can be used to predict overall survival. It contains four components:
(1) n.fjernet is the number of lymph nodes removed on the cervical neck
(2) n.sygdom is the number of lymph nodes with evidence of cancer metastises. Therefore, n.sygdom cannot exceed the number of n.fjernet. If the user tries to choose n.sygdom greater than n.fjernet, the shinyapp should return: Error: Number of positive lymph nodes cannot exceed the lymph nodal yield (written in red)
(3) ecs is extracapsular spread (of metastises, i.e. the metastises penetrating one or more of the lymph nodes) in n.sygdom. Therefore, this option can only be available if n.sygdom ≥ 1
(4) contra.pos is whether the spread (of metastises) includes the uni- or contralateral side of the neck. Therefore, this option is only be available if n.sygdom ≥ 1.
The app function estimates the nomogram-score based on values stored in nom - which is attached below. If n.sygdom equals 0, and therefore unable access to ecs and contra.pos, then ecs and contra.pos should generate/add 0 to the calc_score printed in output$out.score <- renderText(calc_score()), i.e. exclusion from the nomogram.
My script
library(shiny)
library(survminer)
ui <- fluidPage(
titlePanel("Survival Curve"),
sidebarLayout(
sidebarPanel(
sliderInput("n.fjernet", "Lymph Nodal Yield", min = 2, max = 150, value = 30),
sliderInput("n.sygdom", "Number of positive lymph nodes", min = 0, max = 40, value = 0),
radioButtons("ecs", "Extracapsular extension", c("No","Yes")),
radioButtons("contra.pos", "Neck involvement", c("Contra.","Ipsi.")),
verbatimTextOutput("out.score"),
verbatimTextOutput("out.score.group")
),
mainPanel(
plotOutput("surv_plot")
)
)
)
server <- function(input, output, session) {
calc_score <- reactive({
round(nom$ecs$points[nom$ecs$ecs==input$ecs] +
nom$contra.pos$points[nom$contra.pos$contra.pos==input$contra.pos] +
nom$n.fjernet$points[nom$n.fjernet$n.fjernet==input$n.fjernet] +
nom$n.sygdom$points[nom$n.sygdom$n.sygdom==input$n.sygdom],digits=1)
})
calc_score_group <- function(score) {
cut(score, c(0,35.9,55.2,70.0,83.3,Inf), include.lowest = TRUE, labels = c("1","2","3","4","5"))
}
fit_data <- reactive({
p %>% filter(score.group == as.numeric(calc_score_group(calc_score())))
})
fit_model <- reactive({
survfit(Surv(os.neck, mors) ~ 1, data = fit_data())
})
output$out.score <- renderText(calc_score())
output$out.score.group <- renderText(calc_score_group(calc_score()))
output$surv_plot <- renderPlot({
ggsurvplot(
fit_model(),
data = fit_data(),
risk.table = TRUE,
pval = F,
pval.coord = c(0, 0.25),
conf.int = T,
size=1,
xlim = c(0,60),
conf.int.alpha=c(0.2),
break.x.by = 6,
xlab="Time in months",
ylab="Probability of overall survival",
ggtheme = theme,
surv.median.line = "v",
ylim=c(0,1),
palette="#2C77BF",
tables.theme=theme,
legend.title=paste("Score group", calc_score_group(calc_score())),
surv.scale="percent",
tables.col="strata",
risk.table.col = "strata",
risk.table.y.text = FALSE,
tables.y.text = FALSE)
})
}
shinyApp(ui, server)
My data (now with p$score.group)
p <- structure(list(contra.pos = struct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 38L, 50L, 21L, 41L, 74L, 15L,
26L, 36L, 37L, 34L, 22L, 31L, 53L, 13L, 44L, 43L, 51L, 20L,
21L, 63L, 40L, 25L, 17L, 43L, 47L, 35L, 21L, 4L, 23L, 35L,
50L, 69L, 24L, 38L, 45L, 37L, 35L, 25L, 19L, 43L, 19L, 33L,
38L, 50L, 21L, 40L, 100L, 45L, 53L, 41L, 7L, 75L, 48L, 20L,
11L, 72L, 37L, 34L, 70L, 20L, 47L, 44L, 45L, 48L, 23L, 27L,
24L, 39L, 9L, 34L, 22L, 89L, 40L, 35L, 34L, 61L, 28L, 27L,
62L, 47L, 13L, 20L, 9L, 27L, 38L, 44L, 15L, 33L, 65L, 31L,
49L, 53L, 15L, 26L, 17L, 24L, 20L, 25L, 12L, 34L, 22L, 27L,
14L, 27L, 31L, 26L, 15L, 16L, 30L, 19L, 51L, 12L, 33L, 68L,
26L, 20L, 34L, 31L, 7L, 76L, 7L, 24L, 36L, 22L, 27L, 35L,
64L, 18L, 38L, 10L, 27L, 26L, 47L, 15L, 30L, 30L, 21L, 31L,
14L, 14L, 22L, 28L, 13L, 17L, 16L, 7L, 11L, 37L, 55L, 13L,
26L, 17L, 12L, 44L, 58L, 20L, 28L, 7L, 24L, 10L, 42L, 39L,
14L, 31L, 49L), n.sygdom = c(1L, 2L, 1L, 3L, 1L, 0L, 3L,
0L, 2L, 1L, 4L, 4L, 1L, 0L, 2L, 2L, 1L, 0L, 0L, 4L, 0L, 0L,
1L, 1L, 0L, 1L, 4L, 3L, 1L, 0L, 8L, 1L, 1L, 1L, 1L, 1L, 0L,
1L, 2L, 1L, 0L, 2L, 1L, 0L, 2L, 0L, 3L, 0L, 1L, 1L, 1L, 2L,
0L, 3L, 2L, 1L, 0L, 0L, 0L, 2L, 0L, 3L, 0L, 0L, 0L, 1L, 1L,
0L, 0L, 1L, 4L, 0L, 0L, 2L, 2L, 1L, 1L, 0L, 0L, 3L, 1L, 6L,
0L, 0L, 0L, 3L, 2L, 2L, 4L,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
1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L,
0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L,
0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L,
0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L,
1L, 0L, 0L, 1L, 0L, 1L), os.neck = c(9.63, 7.03, 9.17, 10.48,
7.69, 15.18, 13.5, 16.33, 15.31, 12.09, 12.35, 22.28, 15.77,
14.39, 10.02, 14.52, 8.44, 23.82, 5.95, 3.78, 19.32, 20.14,
15.51, 19.78, 12.98, 32.92, 9.76, 5.65, 30.75, 2.79, 33.58,
27.53, 27.63, 14.62, 29.17, 25.4, 18.43, 5.29, 30.75, 28.48,
14.69, 13.14, 6.6, 26.81, 40.74, 11.63, 13.31, 10.41, 9.56,
17.51, 35.78, 35.75, 37.62, 33.25, 36.96, 34.56, 40.05, 41.26,
24.34, 37.49, 40.94, 24.11, 39.33, 11.24, 39.1, 19.75, 38.93,
39.36, 36.34, 48, 29.17, 47.93, 3.68, 24.21, 46.36, 49.12,
50.96, 14.16, 54.01, 19.88, 50.86, 1.87, 54.24, 13.93, 11.6,
10.05, 23.1, 62.78, 12.58, 39, 59.83, 6.77, 60.39, 18.46,
61.77, 58.41, 49.45, 64.26, 2.4, 26.51, 58.94, 69.91, 64.66,
55.56, 46.55, 29.63, 55.66, 19.68, 7.62, 2.73, 17.77, 10.12,
9.95, 74.22, 57.3, 58.94, 27.01, 34.23, 78.82, 27.2, 83.02,
76.68, 58.15, 22.18, 14.49, 3.91, 25.92, 74.64, 66.83, 70.74,
38.08, 7.69, 74.55, 49.94, 11.1, 88.54, 6.44, 79.54, 80.82,
70.83, 12.91, 81.25, 17.38, 29.96, 94.72, 73.53, 72.54, 1.35,
89.69, 62.85, 7.62, 93.27, 5.09, 51.25, 62, 55.33, 44.62,
56.94, 94.55, 88.61, 32.46, 11.04, 16.53, 100.04, 24.74,
24.54, 5.75, 59.83, 59.83, 77.77, 92.78, 49.58, 91.2, 1.18,
18.92, 6.34, 32.46, 72.41, 105.82, 1.84, 12.78, 57.56, 59.14,
104.08, 15.54, 117.75, 4.27, 67.61, 19.78, 112.49, 53.59,
107.01, 47.57, 9.46, 53.59, 46.46, 57.33, 18.76, 82.04, 13.67,
67.45, 28.98, 21.19, 121.4, 91.07, 50.83, 121.72, 123.04,
6.31, 123.5, 58.68, 9.56, 34.1, 90.48, 71.1, 11.33, 65.35,
54.21, 34.99, 62.06), score = c(47.16, 47.55, 39.27, 72.23,
44.91, 25.74, 62.36, 25.74, 55.44, 34.48, 82.32, 76.4, 60.64,
32.22, 52.34, 36.13, 41.81, 34.2, 33.91, 65.66, 32.51, 34.76,
42.37, 38.14, 35.61, 45.75, 61.23, 59.04, 46.6, 33.35, 84.05,
26.5, 38.99, 62.89, 47.16, 38.42, 35.32, 37.01, 56.85, 29.96,
31.66, 60.52, 42.93, 35.04, 62.21, 37.86, 64.96, 35.32, 40.96,
38.71, 47.16, 58.77, 27.71, 54.81, 50.09, 42.65, 28.56, 36.73,
31.1, 43.88, 38.43, 78.15, 32.51, 32.22, 33.07, 47.16, 44.63,
27.71, 38.99, 40.96, 68.56, 28.28, 37.02, 58.83, 58.48, 42.09,
46.32, 37.86, 30.53, 60.73, 55, 77.47, 41.53, 36.17, 32.79,
71.38, 56.79, 57.98, 76.32, 29.97, 63.55, 123.86, 35.61,
59.39, 41.24, 37.3, 33.35, 37.5, 39.27, 58.83, 53.47, 52.02,
35.52, 27.71, 31.1, 51.39, 21.51, 83.34, 37.02, 39.55, 50.79,
91.42, 33.07, 63.65, 70.61, 51.62, 52.34, 29.97, 29.12, 36.17,
35.04, 85.42, 31.66, 40.12, 55.28, 90.67, 51.15, 53.47, 43.5,
55.16, 47.67, 34.76, 35.04, 35.89, 98.47, 38.99, 59.23, 40.12,
57.25, 31.94, 52.46, 49.14, 33.35, 92.46, 33.91, 50.93, 49.8,
38.43, 57.42, 37.86, 35.89, 47.73, 57.82, 39.27, 33.07, 36.45,
57.13, 70.03, 57.25, 71.95, 35.32, 60.64, 38.14, 71.76, 91.52,
61.15, 39.27, 33.35, 56.36, 35.32, 47.73, 43.78, 33.91, 62.77,
75.44, 51.39, 78.71, 78.39, 47.16, 45.75, 55, 24.61, 37.58,
42.65, 62.05, 35.04, 35.32, 51.62, 38.43, 34.2, 34.2, 42.29,
33.91, 49.42, 60.8, 36.45, 56.97, 61.2, 37.86, 38.14, 40.68,
61.77, 54.43, 27.15, 49.7, 46.04, 60.07, 39.27, 130.25, 59.89,
37.02, 40.32, 40.68, 69.48, 39.84, 73.64, 53.87, 60.92, 71.95,
51.05), score.group = structure(c(2L, 2L, 2L, 4L, 2L, 1L,
3L, 1L, 3L, 1L, 4L, 4L, 3L, 1L, 2L, 2L, 2L, 1L, 1L, 3L, 1L,
1L, 2L, 2L, 1L, 2L, 3L, 3L, 2L, 1L, 5L, 1L, 2L, 3L, 2L, 2L,
1L, 2L, 3L, 1L, 1L, 3L, 2L, 1L, 3L, 2L, 3L, 1L, 2L, 2L, 2L,
3L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 4L, 1L, 1L, 1L, 2L,
2L, 1L, 2L, 2L, 3L, 1L, 2L, 3L, 3L, 2L, 2L, 2L, 1L, 3L, 2L,
4L, 2L, 2L, 1L, 4L, 3L, 3L, 4L, 1L, 3L, 5L, 1L, 3L, 2L, 2L,
1L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 5L, 2L, 2L, 2L,
5L, 1L, 3L, 4L, 2L, 2L, 1L, 1L, 2L, 1L, 5L, 1L, 2L, 3L, 5L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 5L, 2L, 3L, 2L, 3L, 1L, 2L,
2L, 1L, 5L, 1L, 2L, 2L, 2L, 3L, 2L, 1L, 2L, 3L, 2L, 1L, 2L,
3L, 4L, 3L, 4L, 1L, 3L, 2L, 4L, 5L, 3L, 2L, 1L, 3L, 1L, 2L,
2L, 1L, 3L, 4L, 2L, 4L, 4L, 2L, 2L, 2L, 1L, 2L, 2L, 3L, 1L,
1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 3L, 2L, 3L, 3L, 2L, 2L, 2L,
3L, 2L, 1L, 2L, 2L, 3L, 2L, 5L, 3L, 2L, 2L, 2L, 3L, 2L, 4L,
2L, 3L, 4L, 2L), .Label = c("1", "2", "3", "4", "5"), class = "factor")), row.names = c(NA,
220L), class = "data.frame")
And
# plot(nom) for nomogram
nom <- structure(list(n.fjernet = structure(list(n.fjernet = c(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, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133), Xbeta = c(`1` = -0.0114560716414661,
`2` = -0.0171841074621991, `3` = -0.0229121432829322, `4` = -0.0286401791036652,
`5` = -0.0343682149243983, `6` = -0.0400962507451313, `7` = -0.0458242865658644,
`8` = -0.0515523223865974, `9` = -0.0572803582073305, `10` = -0.0630083940280635,
`11` = -0.0687364298487966, `12` = -0.0744644656695296, `13` = -0.0801925014902627,
`14` = -0.0859205373109957, `15` = -0.0916485731317288, `16` = -0.0973766089524618,
`17` = -0.103104644773195, `18` = -0.108832680593928, `19` = -0.114560716414661,
`20` = -0.120288752235394, `21` = -0.126016788056127, `22` = -0.13174482387686,
`23` = -0.137472859697593, `24` = -0.143200895518326, `25` = -0.148928931339059,
`26` = -0.154656967159792, `27` = -0.160385002980525, `28` = -0.166113038801258,
`29` = -0.171841074621991, `30` = -0.177569110442725, `31` = -0.183297146263458,
`32` = -0.189025182084191, `33` = -0.194753217904924, `34` = -0.200481253725657,
`35` = -0.20620928954639, `36` = -0.211937325367123, `37` = -0.217665361187856,
`38` = -0.223393397008589, `39` = -0.229121432829322, `40` = -0.234849468650055,
`41` = -0.240577504470788, `42` = -0.246305540291521, `43` = -0.252033576112254,
`44` = -0.257761611932987, `45` = -0.26348964775372, `46` = -0.269217683574453,
`47` = -0.274945719395186, `48` = -0.280673755215919, `49` = -0.286401791036652,
`50` = -0.292129826857386, `51` = -0.297857862678119, `52` = -0.303585898498852,
`53` = -0.309313934319585, `54` = -0.315041970140318, `55` = -0.320770005961051,
`56` = -0.326498041781784, `57` = -0.332226077602517, `58` = -0.33795411342325,
`59` = -0.343682149243983, `60` = -0.349410185064716, `61` = -0.355138220885449,
`62` = -0.360866256706182, `63` = -0.366594292526915, `64` = -0.372322328347648,
`65` = -0.378050364168381, `66` = -0.383778399989114, `67` = -0.389506435809847,
`68` = -0.39523447163058, `69` = -0.400962507451313, `70` = -0.406690543272047,
`71` = -0.41241857909278, `72` = -0.418146614913513, `73` = -0.423874650734246,
`74` = -0.429602686554979, `75` = -0.435330722375712, `76` = -0.441058758196445,
`77` = -0.446786794017178, `78` = -0.452514829837911, `79` = -0.458242865658644,
`80` = -0.463970901479377, `81` = -0.46969893730011, `82` = -0.475426973120843,
`83` = -0.481155008941576, `84` = -0.486883044762309, `85` = -0.492611080583042,
`86` = -0.498339116403775, `87` = -0.504067152224508, `88` = -0.509795188045241,
`89` = -0.515523223865974, `90` = -0.521251259686707, `91` = -0.526979295507441,
`92` = -0.532707331328174, `93` = -0.538435367148907, `94` = -0.54416340296964,
`95` = -0.549891438790373, `96` = -0.555619474611106, `97` = -0.561347510431839,
`98` = -0.567075546252572, `99` = -0.572803582073305, `100` = -0.578531617894038,
`101` = -0.584259653714771, `102` = -0.589987689535504, `103` = -0.595715725356237,
`104` = -0.60144376117697, `105` = -0.607171796997703, `106` = -0.612899832818436,
`107` = -0.618627868639169, `108` = -0.624355904459902, `109` = -0.630083940280635,
`110` = -0.635811976101369, `111` = -0.641540011922102, `112` = -0.647268047742835,
`113` = -0.652996083563568, `114` = -0.658724119384301, `115` = -0.664452155205034,
`116` = -0.670180191025767, `117` = -0.6759082268465, `118` = -0.681636262667233,
`119` = -0.687364298487966, `120` = -0.693092334308699, `121` = -0.698820370129432,
`122` = -0.704548405950165, `123` = -0.710276441770898, `124` = -0.716004477591631,
`125` = -0.721732513412364, `126` = -0.727460549233097, `127` = -0.73318858505383,
`128` = -0.738916620874563, `129` = -0.744644656695296, `130` = -0.750372692516029,
`131` = -0.756100728336763, `132` = -0.761828764157496), points = c(`1` = 27.84103949255,
`2` = 27.6285124735229, `3` = 27.4159854544958, `4` = 27.2034584354687,
`5` = 26.9909314164416, `6` = 26.7784043974145, `7` = 26.5658773783874,
`8` = 26.3533503593603, `9` = 26.1408233403332, `10` = 25.9282963213061,
`11` = 25.715769302279, `12` = 25.5032422832519, `13` = 25.2907152642248,
`14` = 25.0781882451977, `15` = 24.8656612261706, `16` = 24.6531342071435,
`17` = 24.4406071881164, `18` = 24.2280801690893, `19` = 24.0155531500622,
`20` = 23.8030261310351, `21` = 23.590499112008, `22` = 23.3779720929809,
`23` = 23.1654450739538, `24` = 22.9529180549267, `25` = 22.7403910358996,
`26` = 22.5278640168725, `27` = 22.3153369978454, `28` = 22.1028099788183,
`29` = 21.8902829597912, `30` = 21.6777559407641, `31` = 21.465228921737,
`32` = 21.2527019027099, `33` = 21.0401748836828, `34` = 20.8276478646557,
`35` = 20.6151208456286, `36` = 20.4025938266015, `37` = 20.1900668075744,
`38` = 19.9775397885473, `39` = 19.7650127695202, `40` = 19.5524857504931,
`41` = 19.339958731466, `42` = 19.1274317124389, `43` = 18.9149046934118,
`44` = 18.7023776743847, `45` = 18.4898506553576, `46` = 18.2773236363305,
`47` = 18.0647966173034, `48` = 17.8522695982763, `49` = 17.6397425792492,
`50` = 17.4272155602221, `51` = 17.214688541195, `52` = 17.0021615221679,
`53` = 16.7896345031408, `54` = 16.5771074841137, `55` = 16.3645804650866,
`56` = 16.1520534460595, `57` = 15.9395264270324, `58` = 15.7269994080053,
`59` = 15.5144723889782, `60` = 15.3019453699511, `61` = 15.089418350924,
`62` = 14.8768913318969, `63` = 14.6643643128698, `64` = 14.4518372938427,
`65` = 14.2393102748156, `66` = 14.0267832557885, `67` = 13.8142562367614,
`68` = 13.6017292177343, `69` = 13.3892021987072, `70` = 13.1766751796801,
`71` = 12.964148160653, `72` = 12.7516211416259, `73` = 12.5390941225988,
`74` = 12.3265671035717, `75` = 12.1140400845446, `76` = 11.9015130655175,
`77` = 11.6889860464904, `78` = 11.4764590274633, `79` = 11.2639320084362,
`80` = 11.0514049894091, `81` = 10.838877970382, `82` = 10.6263509513549,
`83` = 10.4138239323278, `84` = 10.2012969133007, `85` = 9.98876989427365,
`86` = 9.77624287524655, `87` = 9.56371585621945, `88` = 9.35118883719235,
`89` = 9.13866181816525, `90` = 8.92613479913816, `91` = 8.71360778011105,
`92` = 8.50108076108396, `93` = 8.28855374205686, `94` = 8.07602672302976,
`95` = 7.86349970400266, `96` = 7.65097268497556, `97` = 7.43844566594846,
`98` = 7.22591864692136, `99` = 7.01339162789426, `100` = 6.80086460886717,
`101` = 6.58833758984007, `102` = 6.37581057081297, `103` = 6.16328355178587,
`104` = 5.95075653275877, `105` = 5.73822951373167, `106` = 5.52570249470457,
`107` = 5.31317547567747, `108` = 5.10064845665037, `109` = 4.88812143762328,
`110` = 4.67559441859617, `111` = 4.46306739956908, `112` = 4.25054038054198,
`113` = 4.03801336151488, `114` = 3.82548634248778, `115` = 3.61295932346068,
`116` = 3.40043230443358, `117` = 3.18790528540648, `118` = 2.97537826637939,
`119` = 2.76285124735228, `120` = 2.55032422832519, `121` = 2.33779720929809,
`122` = 2.12527019027099, `123` = 1.91274317124389, `124` = 1.70021615221679,
`125` = 1.48768913318969, `126` = 1.27516211416259, `127` = 1.06263509513549,
`128` = 0.850108076108397, `129` = 0.637581057081296, `130` = 0.425054038054198,
`131` = 0.212527019027097, `132` = 0)), info = list(nfun = 3L,
predictor = "n.fjernet", effect.name = "n.fjernet", type = "main")),
n.sygdom = structure(list(n.sygdom = c(0, 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), Xbeta = c(`133` = 0, `134` = 0.32236136668714,
`135` = 0.648650531337351, `136` = 0.909274081797897, `137` = 1.09719119915252,
`138` = 1.2269431700224, `139` = 1.31307128102872, `140` = 1.37011681879267,
`141` = 1.41262106993544, `142` = 1.452701773308, `143` = 1.49278247668057,
`144` = 1.53286318005315, `145` = 1.57294388342572, `146` = 1.61302458679829,
`147` = 1.65310529017085, `148` = 1.69318599354344, `149` = 1.733266696916,
`150` = 1.77334740028855, `151` = 1.81342810366113, `152` = 1.8535088070337,
`153` = 1.89358951040629, `154` = 1.93367021377884, `155` = 1.97375091715141,
`156` = 2.01383162052397, `157` = 2.05391232389658, `158` = 2.09399302726916,
`159` = 2.13407373064171, `160` = 2.17415443401433, `161` = 2.21423513738691,
`162` = 2.25431584075947, `163` = 2.29439654413205, `164` = 2.33447724750454,
`165` = 2.37455795087723, `166` = 2.41463865424957, `167` = 2.45471935762221,
`168` = 2.49480006099482, `169` = 2.53488076436739, `170` = 2.57496146774009,
`171` = 2.61504217111266, `172` = 2.65512287448523, `173` = 2.69520357785787
), points = c(`133` = 0, `134` = 11.9605572408505, `135` = 24.0668473679043,
`136` = 33.7367495824038, `137` = 40.7090287415156, `138` = 45.5232094563172,
`139` = 48.7188163378863, `140` = 50.8353739973004, `141` = 52.412407045637,
`142` = 53.8995193254604, `143` = 55.3866316052841, `144` = 56.8737438851078,
`145` = 58.3608561649314, `146` = 59.8479684447552, `147` = 61.3350807245785,
`148` = 62.8221930044026, `149` = 64.309305284226, `150` = 65.7964175640487,
`151` = 67.283529843873, `152` = 68.7706421236966, `153` = 70.257754403521,
`154` = 71.7448666833438, `155` = 73.2319789631674, `156` = 74.7190912429907,
`157` = 76.2062035228159, `158` = 77.6933158026398, `159` = 79.1804280824625,
`160` = 80.6675403622881, `161` = 82.1546526421122, `162` = 83.6417649219352,
`163` = 85.1288772017594, `164` = 86.6159894815798, `165` = 88.103101761408,
`166` = 89.5902140412232, `167` = 91.0773263210494, `168` = 92.5644386008743,
`169` = 94.0515508806979, `170` = 95.5386631605266, `171` = 97.0257754403502,
`172` = 98.5128877201739, `173` = 100)), info = list(nfun = 3L,
predictor = "n.sygdom", effect.name = "n.sygdom", type = "main")),
ecs = structure(list(ecs = c("No", "Yes"), Xbeta = c(`174` = 0,
`175` = 0.352802098746005), points = c(`174` = 0, `175` = 13.0899981598574
)), info = list(nfun = 3L, predictor = "ecs", effect.name = "ecs",
type = "main")), contra.pos = structure(list(contra.pos = c("Ipsi.",
"Contra."), Xbeta = c(`176` = 0, `177` = -0.149053853083395
), points = c(`176` = 5.53033745977221, `177` = 0)), info = list(
nfun = 3L, predictor = "contra.pos", effect.name = "contra.pos",
type = "main")), total.points = list(x = c(0, 10, 20,
30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140)), lp = list(
x = c(8.59901355289166, 27.1504878870641, 45.7019622212365,
64.253436555409, 82.8049108895814, 101.356385223754,
119.907859557926, 138.459333892099), x.real = c(-1, -0.5,
0, 0.5, 1, 1.5, 2, 2.5)), `Probability of 1 year survival` = list(
x = c(132.923978485611, 122.154519662532, 112.023605643525,
101.668496222993, 90.3441422980089, 77.0166169199793,
59.6149679036176, 31.771904926561), x.real = c(0.2, 0.3,
0.4, 0.5, 0.6, 0.7, 0.8, 0.9), fat = c("0.2", "0.3",
"0.4", "0.5", "0.6", "0.7", "0.8", "0.9"), which = c(FALSE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE
)), `Probability of 3 years survival` = list(x = c(111.455658509363,
98.1672795067317, 87.3978451509886, 77.2669361851509, 66.9118109221416,
55.5874579746061, 42.2599719337723, 24.8583283615229), x.real = c(0.1,
0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8), fat = c("0.1", "0.2",
"0.3", "0.4", "0.5", "0.6", "0.7", "0.8"), which = c(FALSE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE)),
`Probability of 5 years survival` = list(x = c(96.3366217164868,
83.0483098712202, 72.2788509036931, 62.1479468853665, 51.7928216700398,
40.468478298201, 27.1409533137375, 9.73931852863156), x.real = c(0.1,
0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8), fat = c("0.1", "0.2",
"0.3", "0.4", "0.5", "0.6", "0.7", "0.8"), which = c(FALSE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE))), info = list(
fun = list(function (x)
surv(12, x), function (x)
surv(36, x), function (x)
surv(60, x)), lp = TRUE, lp.at = c(-1, -0.5, 0, 0.5, 1, 1.5,
2, 2.5), discrete = c(n.fjernet = FALSE, n.sygdom = FALSE,
ecs = TRUE, contra.pos = TRUE, studie = TRUE), funlabel = c("Probability of 1 year survival",
"Probability of 3 years survival", "Probability of 5 years survival"
), fun.at = NULL, fun.lp.at = NULL, Abbrev = list(), minlength = 4,
conf.int = FALSE, R = structure(c(-0.761828764157496, -0.0114560716414661,
0, 2.69520357785787, 0, 0.352802098746005, -0.149053853083395,
0), .Dim = c(2L, 4L), .Dimnames = list(NULL, c("n.fjernet",
"n.sygdom", "ecs", "contra.pos"))), sc = 37.1029486683449,
maxscale = 100, Intercept = -1.23176092093802, nint = 10,
space.used = c(main = 4, ia = 0)), class = "nomogram")
your first problem can be solved with an updateSliderInput call where you update the max value to be equal the selected value from the slider above.
The second problem can besolved with an conditionalPanel here I needed to change the naming of the n.sygdom slider to n_sygdom because the java script couldn't handle to dot notation. I would recommend you to the same for all you variables whenever you are working with shiny.
Below is working example
ui <- fluidPage(
titlePanel("Survival Curve"),
sidebarLayout(
sidebarPanel(
sliderInput("n.fjernet", "Lymph Nodal Yield", min = 2, max = 150, value = 40),
sliderInput("n_sygdom", "Number of positive lymph nodes", min = 0, max = 40, value = 0),
conditionalPanel(
condition = "input.n_sygdom >= 1",
radioButtons("ecs", "Extracapsular extension", c("No","Yes")),
radioButtons("contra.pos", "Neck involvement", c("Contra.","Ipsi.")
)
),
verbatimTextOutput("out.score"),
verbatimTextOutput("out.score.group")
),
mainPanel(
plotOutput("surv_plot")
)
)
)
server <- function(input, output, session) {
calc_score <- reactive({
round(nom$ecs$points[nom$ecs$ecs==input$ecs] +
nom$contra.pos$points[nom$contra.pos$contra.pos==input$contra.pos] +
nom$n.fjernet$points[nom$n.fjernet$n.fjernet==input$n.fjernet] +
nom$n_sygdom$points[nom$n_sygdom$n_sygdom==input$n_sygdom],digits=1)
})
observe(
updateSliderInput(
session = session,
inputId = "n_sygdom",
max = min(40, input$n.fjernet),
value = min(input$n.fjernet, input$n_sygdom)
)
)
calc_score_group <- function(score) {
cut(score, c(0,35.9,55.2,70.0,83.3,Inf), include.lowest = TRUE, labels = c("1","2","3","4","5"))
}
fit_data <- reactive({
p %>% filter(score.group == as.numeric(calc_score_group(calc_score())))
})
fit_model <- reactive({
survfit(Surv(os.neck, mors) ~ 1, data = fit_data())
})
output$out.score <- renderText(calc_score())
output$out.score.group <- renderText(calc_score_group(calc_score()))
output$surv_plot <- renderPlot({
ggsurvplot(
fit_model(),
data = fit_data(),
risk.table = TRUE,
pval = F,
pval.coord = c(0, 0.25),
conf.int = T,
size=1,
xlim = c(0,60),
conf.int.alpha=c(0.2),
break.x.by = 6,
xlab="Time in months",
ylab="Probability of overall survival",
ggtheme = theme,
surv.median.line = "v",
ylim=c(0,1),
palette="#2C77BF",
tables.theme=theme,
legend.title=paste("Score group", calc_score_group(calc_score())),
surv.scale="percent",
tables.col="strata",
risk.table.col = "strata",
risk.table.y.text = FALSE,
tables.y.text = FALSE)
})
}
please not that I changed the naming also in the data set as well
Hope this helps!!

Why does strip text color from facet_wrap not correspond to element_text color?

Please, find my data sample p below.
Question: why does the strip text color from facet_wrap() not change as specified in element_text(colour)?
I have produced this plot
I would like the strip text color (UICC Stage I, II, III and IV) to match the color of the geom_point as specified in cols. It currently loads #E1B930 on all text items.
What is wrong with the following script?
cols = c("#E1B930", "#2C77BF","#E38072","#6DBCC3")
ggplot(p, aes(x=n.fjernet,y=os.neck)) + geom_point(aes(color=uiccc),shape=20, size=5,alpha=0.7) +
geom_quantile(quantiles = 0.5,col="black", size=1,linetype=2) + facet_wrap(.~factor(uiccc)) +
scale_fill_manual(values=cols) +
scale_colour_manual(values=cols) +
scale_x_continuous(breaks = seq(0,50, by=10), name="Lymph nodal yield") +
scale_y_continuous(name="Time to death") +
theme(strip.text.x = element_text(size=12,face="bold", colour = cols),
strip.text.y = element_text(size=12, face="bold"),
strip.background = element_rect(fill="white"),
legend.position="none")
My data
p <- structure(list(uiccc = structure(c(4L, 3L, 3L, 2L, 2L, 2L, 2L,
4L, 1L, 1L, 2L, 1L, 4L, 2L, 1L, 2L, 3L, 1L, 2L, 3L, 2L, 1L, 2L,
3L, 2L, 4L, 1L, 1L, 2L, 4L, 4L, 1L, 3L, 3L, 4L, 3L, 1L, 4L, 2L,
3L, 4L, 4L, 4L, 3L, 2L, 4L, 1L, 4L, 2L, 4L, 4L, 2L, 4L, 4L, 1L,
4L, 2L, 3L, 2L, 2L, 3L, 2L, 4L, 4L, 2L, 2L, 3L, 1L, 4L, 4L, 4L,
4L, 4L, 3L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 4L,
2L, 4L, 1L, 2L, 1L, 1L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 3L,
3L, 4L, 1L, 1L, 3L, 1L, 4L, 2L, 1L, 3L, 1L, 2L, 1L, 1L, 4L, 1L,
1L, 4L, 1L, 1L, 3L, 2L, 2L, 1L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 2L,
2L, 4L, 4L, 2L, 3L, 4L, 2L, 4L, 1L, 1L, 3L, 3L, 1L, 1L, 3L, 4L,
4L, 2L, 4L, 4L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 2L, 2L, 4L, 3L,
1L, 4L, 3L, 4L, 4L, 3L, 1L, 4L, 4L, 4L, 4L, 2L, 2L, 4L, 4L, 1L,
4L, 4L, 2L, 4L, 4L, 4L, 3L, 4L, 3L, 3L, 4L, 4L, 2L, 4L, 4L, 2L,
4L, 4L, 4L, 4L, 1L, 4L, 4L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 2L, 3L, 1L, 2L, 1L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 1L,
3L, 4L, 4L, 1L, 3L, 3L, 4L, 3L), .Label = c("UICC Stage I", "UICC Stage II",
"UICC Stage III", "UICC Stage IV"), class = "factor"), os.neck = c(11.5,
74.38, 17.02, 7.89, 96.03, 40.48, 17.74, 14.65, 62.46, 12.55,
9.92, 26.05, 45.47, 17.38, 39.72, 51.45, 8.61, 76.98, 67.09,
94.79, 72.15, 93.93, 17.05, 12.48, 91.6, 15.87, 11.04, 67.22,
67.02, 8.94, 6.6, 5.09, 10.68, 17.15, 0.07, 5.19, 40.77, 0.2,
170.88, 5.55, 1.61, 38.28, 10.58, 32.99, 110.98, 103.69, 122.32,
14.78, 42.74, 4.04, 8.28, 84.96, 11.7, 49.97, 120.48, 52.6, 71.26,
16.3, 100.14, 55.03, 6.51, 89.89, 51.71, 24.97, 55.66, 21.91,
81.48, 30.92, 1.58, 7.52, 30.75, 3.45, 19.22, 5.42, 17.68, 45.54,
76.22, 125.34, 83.62, 30.82, 90.32, 1.84, 19.98, 20.53, 32.59,
54.77, 2.3, 106.84, 22.28, 45.18, 4.47, 39.66, 32.3, 16.23, 3.88,
2.23, 0.23, 18.73, 0.79, 28.75, 79.54, 14.46, 15.15, 54.97, 48.59,
34.83, 58.42, 35.29, 45.73, 57.53, 63.11, 65.05, 29.54, 77.21,
63.48, 83.35, 34.3, 64.49, 29.54, 62.69, 21.62, 49.35, 99.02,
15.8, 41.89, 12.98, 13.8, 43.6, 57.23, 31.38, 70.74, 39.46, 20.76,
67.22, 127.15, 74.12, 1.97, 7.39, 25.17, 28.22, 14, 36.53, 20.83,
19.55, 40.77, 27.76, 45.31, 34.46, 35.55, 26.94, 9.43, 10.51,
6.8, 8.18, 8.02, 14.29, 6.11, 13.8, 4.9, 4.04, 14.82, 11.66,
73.07, 92.91, 99.98, 10.64, 10.05, 95.8, 7.23, 12.81, 43.99,
13.9, 10.25, 16.36, 18.2, 18.76, 12.32, 8.64, 11.79, 112.04,
70.97, 31.28, 28.85, 21.49, 19.94, 22.14, 29.44, 67.62, 11.01,
45.24, 110.72, 20.24, 14.06, 12.88, 31.51, 8.08, 13.08, 21.45,
24.28, 21.98, 32.89, 23.26, 15.41, 15.41, 13.8, 40.12, 8.02,
15.77, 49.81, 18.17, 24.21, 47.08, 6.6, 37.16, 13.01, 8.38, 14.36,
18.27, 17.28, 73.76, 68.21, 22.83, 2.66, 69.06, 17.05, 8.61,
23.33, 13.34, 12.65, 8.77, 128.92, 16.1, 4.99, 11.73, 22.97,
40.12, 20.37, 2.04, 45.73), mors = c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 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4L, 6L, 10L, 8L, 4L, 9L, 10L,
14L, 14L, 3L, 4L, 6L, 6L, 20L, 3L, 26L, 13L, 13L, 13L, 13L, 3L,
7L, 6L, 5L, 10L, 15L, 29L, 7L, 6L, 11L, 17L, 14L, 18L, 22L, 9L,
20L, 34L, 9L, 8L, 8L, 11L, 3L, 4L, 4L, 5L, 3L, 2L, 8L, 5L, 18L,
7L, 9L, 13L, 18L, 19L, 14L, 46L, 23L, 11L, 6L, 18L, 20L, 4L,
2L, 7L, 7L, 4L, 11L, 13L, 13L, 9L, 9L, 9L, 12L, 11L, 16L, 6L,
13L, 8L, 17L, 5L, 8L, 22L, 19L, 3L, 15L, 14L, 7L, 18L, 9L, 10L,
18L, 24L, 11L, 15L, 7L, 6L, 4L, 24L, 23L, 8L, 20L, 9L, 22L, 11L,
2L, 24L, 15L, 5L, 8L, 11L, 11L, 11L, 15L, 6L, 16L, 7L, 9L, 16L,
11L, 33L, 27L, 16L, 57L, 5L, 7L, 8L, 11L, 15L, 15L, 12L, 5L,
9L, 49L, 11L, 28L, 19L, 13L, 23L, 11L, 12L, 10L, 4L, 14L, 6L,
12L, 32L, 13L, 12L, 4L, 11L, 17L, 10L, 5L, 15L, 21L, 19L, 11L,
31L, 9L, 20L, 11L, 16L, 12L, 6L, 16L, 27L, 30L, 18L, 18L, 10L,
7L, 23L, 16L, 15L, 4L, 12L, 9L, 10L, 11L, 7L, 8L, 8L, 7L, 6L,
9L, 9L, 13L, 15L, 12L, 35L, 12L, 5L, 19L, 27L, 34L, 10L, 16L,
18L, 6L, 22L)), row.names = c(3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 20L, 22L, 24L, 28L, 29L,
31L, 34L, 35L, 39L, 40L, 42L, 43L, 44L, 47L, 48L, 49L, 50L, 54L,
56L, 57L, 58L, 59L, 60L, 62L, 63L, 66L, 67L, 68L, 69L, 70L, 71L,
72L, 73L, 74L, 75L, 76L, 80L, 81L, 82L, 83L, 86L, 87L, 88L, 89L,
94L, 97L, 99L, 101L, 102L, 106L, 113L, 115L, 117L, 122L, 129L,
132L, 136L, 142L, 143L, 145L, 146L, 148L, 153L, 154L, 158L, 159L,
163L, 164L, 167L, 169L, 171L, 174L, 175L, 178L, 179L, 185L, 188L,
191L, 197L, 210L, 218L, 220L, 230L, 236L, 238L, 239L, 240L, 241L,
242L, 243L, 244L, 245L, 246L, 247L, 248L, 249L, 250L, 252L, 253L,
254L, 255L, 256L, 257L, 258L, 259L, 261L, 262L, 263L, 264L, 265L,
266L, 270L, 275L, 277L, 278L, 280L, 282L, 284L, 286L, 289L, 293L,
295L, 301L, 302L, 303L, 304L, 305L, 306L, 307L, 308L, 310L, 312L,
313L, 314L, 315L, 316L, 317L, 318L, 319L, 320L, 321L, 322L, 323L,
325L, 327L, 328L, 329L, 330L, 331L, 332L, 333L, 334L, 335L, 336L,
338L, 348L, 349L, 351L, 352L, 353L, 354L, 357L, 358L, 359L, 360L,
361L, 362L, 363L, 365L, 366L, 368L, 371L, 372L, 374L, 376L, 378L,
379L, 380L, 381L, 382L, 383L, 384L, 385L, 386L, 387L, 388L, 389L,
390L, 391L, 392L, 393L, 394L, 395L, 396L, 397L, 398L, 399L, 400L,
401L, 402L, 403L, 405L, 407L, 409L, 410L, 411L, 412L, 413L, 414L,
415L, 416L, 417L, 418L, 419L, 421L, 422L, 424L, 425L, 426L, 427L,
428L, 429L, 430L), class = "data.frame")
This is a modification of grob values for strip.text color using the grid package:
library(grid)
library(ggplot2)
g <- ggplot_gtable(ggplot_build(plot))
strip_both <- which(grepl('strip-', g$layout$name))
colors = c("#E38072","#6DBCC3", "#E1B930", "#2C77BF")
k <- 1
for (i in strip_both) {
j <- which(grepl("text", g$grobs[[i]]$grobs[[1]]$childrenOrder))
g$grobs[[i]]$grobs[[1]]$children[[j]]$children[[1]]$gp$col <- colors[k]
k <- k+1
}
grid.draw(g)
Assigning plot object to plot:
cols = c("#E1B930", "#2C77BF","#E38072","#6DBCC3")
plot <- ggplot(p, aes(x=n.fjernet,y=os.neck)) + geom_point(aes(color=uiccc),shape=20, size=5,alpha=0.7) +
geom_quantile(quantiles = 0.5,col="black", size=1,linetype=2) + facet_wrap(.~factor(uiccc)) +
scale_fill_manual(values=cols) +
scale_colour_manual(values=cols) +
scale_x_continuous(breaks = seq(0,50, by=10), name="Lymph nodal yield") +
scale_y_continuous(name="Time to death") +
theme(strip.text.x = element_text(size=12,face="bold"),
strip.text.y = element_text(size=12, face="bold"),
strip.background = element_rect(fill="white"),
legend.position="none")
Alternatively, plot them per group, then combine:
# named colours per group
cols <- setNames(c("#E1B930", "#2C77BF","#E38072","#6DBCC3"),
levels(p$uiccc))
# set pretty limits
Xlim <- round(range(p$n.fjernet), -1)
Ylim <- round(range(p$os.neck), -1)
ggList <- lapply(split(p, p$uiccc), function(i){
title <- i[1, "uiccc"]
ggplot(i, aes(x = n.fjernet, y = os.neck)) +
geom_point(aes(color = uiccc), shape = 20, size = 5, alpha = 0.7, show.legend = FALSE) +
geom_quantile(quantiles = 0.5, col = "black", size = 1, linetype = 2) +
ggtitle(title) +
scale_fill_manual(values = cols) +
scale_colour_manual(values = cols) +
scale_x_continuous(limits = Xlim) +
scale_y_continuous(limits = Ylim) +
theme_classic() +
theme(plot.title = element_text(colour = cols[ title ]))
})
Then use patchwork or cowplot to combine:
patchwork::wrap_plots(ggList)
#or
cowplot::plot_grid(plotlist = ggList)
Alternatively to #Greg's answer (that I think should be the validated answer), you can get the same plot by adding annotation in place of facet labeling:
library(tidyverse)
ggplot(df, aes(x=n.fjernet,y=os.neck)) + geom_point(aes(color=uiccc),shape=20, size=5,alpha=0.7) +
geom_quantile(quantiles = 0.5,col="black", size=1,linetype=2) + facet_wrap(.~factor(uiccc)) +
scale_fill_manual(values=cols) +
scale_colour_manual(values=cols) +
scale_x_continuous(breaks = seq(0,50, by=10), name="Lymph nodal yield") +
scale_y_continuous(name="Time to death") +
theme(#strip.text.x = element_text(size=12,face="bold", colour = cols),
#strip.text.y = element_text(size=12, face="bold"),
#strip.background = element_rect(fill="white"),
strip.background = element_blank(),
strip.text = element_text(color = "transparent"),
legend.position="none",
plot.margin = unit(c(1,3,1,1), "lines")) +
coord_cartesian(clip = "off",ylim = c(0,175))+
geom_text(data = . %>% distinct(uiccc),
aes(label = factor(uiccc), color = uiccc), y = 200, x = 30, hjust = 0.5, fontface = "bold")

R how to use sjPlot::tab_model() to put lmer, glmer, and gamlss models into a table

I am looking to make a summary table for a set of linear models. The models are either lmer(), glmer(), or gamlss(). I am trying to print the results of 6 of these models into a single table. However, when I try to do this with sjPlot::tab_model, I receive the following error message, "Error: $ operator is invalid for atomic vectors".
I removed the two gamlss() models to see if the table would print and it did. It seems to me that the issue is that sjPlot::tab_model cannot work with gamlss() models.
Databases
recruitment_data <- structure(list(Site_long = 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, 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("Hanauma Bay",
"Waikiki"), class = "factor"), Shelter = 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, 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, 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), .Label = c("High",
"Low"), class = "factor"), `Module #` = structure(c(7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L), .Label = c("111", "112", "113", "114", "115",
"116", "211", "212", "213", "214", "215", "216"), class = "factor"),
TimeStep = c(4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 4L, 4L, 5L,
5L, 6L, 6L, 7L, 7L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 4L, 4L,
5L, 5L, 6L, 6L, 7L, 7L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 4L,
4L, 5L, 5L, 6L, 6L, 7L, 7L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L,
4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 4L, 4L, 5L, 5L, 6L, 6L, 7L,
7L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 4L, 4L, 5L, 5L, 6L, 6L,
7L, 7L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L), Side = 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, 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, 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, 1L, 2L, 1L, 2L), .Label = c("N", "S"), class = "factor"),
recruits = c(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 2, 1,
0, 0, 3, 0, 0, 1, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2,
3, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0,
0, 2, 2, 0, 1, 1, 0, 1, 3, 1, 0, 1, 1, 0, 1, 5, 2, 0, 1,
1, 2, 0, 3, 1, 2, 2, 3, 6, 5, 2, 0, 1, 2, 0, 4, 1, 4, 1,
0, 0, 4, 0, 1)), row.names = c(NA, -96L), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), vars = c("Site_long", "Shelter",
"Module #", "TimeStep"), drop = TRUE)
survival_data <- structure(list(Date = structure(c(17288, 17288, 17288, 17288,
17288, 17288, 17292, 17299, 17299, 17304, 17306, 17386, 17386,
17386, 17386, 17386, 17386, 17387, 17387, 17387, 17389, 17389,
17389, 17390, 17398, 17404, 17475, 17475, 17477, 17480, 17482,
17484, 17484, 17484, 17484, 17484, 17484, 17489, 17575, 17575,
17575, 17575, 17575, 17582, 17586, 17594, 17600, 17601, 17603,
17603), class = "Date"), Year = 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, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("17",
"18"), class = "factor"), Site = structure(c(1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("HAN",
"WAI"), class = "factor"), Treatment = c("CLO", "CLO", "CLO",
"OPE", "OPE", "OPE", "CLO", "CLO", "OPE", "OPE", "CLO", "CLO",
"CLO", "CLO", "OPE", "OPE", "OPE", "CLO", "OPE", "OPE", "CLO",
"CLO", "OPE", "OPE", "CLO", "CLO", "CLO", "OPE", "CLO", "OPE",
"CLO", "CLO", "CLO", "CLO", "OPE", "OPE", "OPE", "OPE", "CLO",
"CLO", "CLO", "OPE", "OPE", "OPE", "CLO", "OPE", "OPE", "CLO",
"CLO", "OPE"), `Module #` = c(212L, 214L, 216L, 211L, 213L, 215L,
116L, 114L, 115L, 113L, 112L, 212L, 214L, 216L, 211L, 213L, 215L,
116L, 111L, 115L, 112L, 114L, 115L, 113L, 114L, 114L, 112L, 115L,
116L, 113L, 114L, 212L, 214L, 216L, 211L, 213L, 215L, 111L, 212L,
214L, 216L, 213L, 215L, 211L, 116L, 115L, 113L, 114L, 112L, 111L
), n.x = c(1L, 1L, 2L, 2L, 3L, 3L, 6L, 7L, 5L, 4L, 2L, 2L, 2L,
1L, 2L, 3L, 5L, 10L, 1L, 4L, 10L, 13L, 6L, 5L, 2L, 2L, 8L, 6L,
10L, 8L, 12L, 2L, 6L, 2L, 2L, 3L, 5L, 2L, 2L, 5L, 1L, 8L, 9L,
2L, 10L, 15L, 10L, 16L, 12L, 4L), n.y = c(1, 1, 0, 2, 3, 3, 6,
7, 4, 4, 2, 2, 2, 1, 2, 3, 5, 9, 1, 3, 10, 11, 5, 5, 1, 1, 7,
6, 7, 8, 11, 2, 5, 2, 2, 3, 5, 2, 2, 5, 1, 7, 7, 0, 8, 14, 9,
9, 9, 4), `%_Survival` = c(100, 100, 0, 100, 100, 100, 100, 100,
80, 100, 100, 100, 100, 100, 100, 100, 100, 90, 100, 75, 100,
84.6153846153846, 83.3333333333333, 100, 50, 50, 87.5, 100, 70,
100, 91.6666666666667, 100, 83.3333333333333, 100, 100, 100,
100, 100, 100, 100, 100, 87.5, 77.7777777777778, 0, 80, 93.3333333333333,
90, 56.25, 75, 100), Quarter = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), Mortality = c(0,
0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 2,
1, 0, 1, 1, 1, 0, 3, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,
2, 2, 1, 1, 7, 3, 0), Survival = c(100, 100, 0, 100, 100, 100,
100, 100, 80, 100, 100, 100, 100, 100, 100, 100, 100, 90, 100,
75, 100, 84.6153846153846, 83.3333333333333, 100, 50, 50, 87.5,
100, 70, 100, 91.6666666666667, 100, 83.3333333333333, 100, 100,
100, 100, 100, 100, 100, 100, 87.5, 77.7777777777778, 0, 80,
93.3333333333333, 90, 56.25, 75, 100), Module = c(212L, 214L,
216L, 211L, 213L, 215L, 116L, 114L, 115L, 113L, 112L, 212L, 214L,
216L, 211L, 213L, 215L, 116L, 111L, 115L, 112L, 114L, 115L, 113L,
114L, 114L, 112L, 115L, 116L, 113L, 114L, 212L, 214L, 216L, 211L,
213L, 215L, 111L, 212L, 214L, 216L, 213L, 215L, 211L, 116L, 115L,
113L, 114L, 112L, 111L), Survival_prop = c(1, 1, 0, 1, 1, 1,
1, 1, 0.8, 1, 1, 1, 1, 1, 1, 1, 1, 0.9, 1, 0.75, 1, 0.846153846153846,
0.833333333333333, 1, 0.5, 0.5, 0.875, 1, 0.7, 1, 0.916666666666667,
1, 0.833333333333333, 1, 1, 1, 1, 1, 1, 1, 1, 0.875, 0.777777777777778,
0, 0.8, 0.933333333333333, 0.9, 0.5625, 0.75, 1), Date_new = structure(c(17378,
17378, 17378, 17378, 17378, 17378, 17382, 17389, 17389, 17394,
17396, 17476, 17476, 17476, 17476, 17476, 17476, 17477, 17477,
17477, 17479, 17479, 17479, 17480, 17488, 17494, 17565, 17565,
17567, 17570, 17572, 17574, 17574, 17574, 17574, 17574, 17574,
17579, 17665, 17665, 17665, 17665, 17665, 17672, 17676, 17684,
17690, 17691, 17693, 17693), class = "Date"), Site_long = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L), .Label = c("Hanauma Bay", "Waikiki"), class = "factor"),
Treatment_long = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 1L,
2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 2L), .Label = c("Closed",
"Open"), class = "factor"), Shelter = c("Low", "Low", "Low",
"High", "High", "High", "Low", "Low", "High", "High", "Low",
"Low", "Low", "Low", "High", "High", "High", "Low", "High",
"High", "Low", "Low", "High", "High", "Low", "Low", "Low",
"High", "Low", "High", "Low", "Low", "Low", "Low", "High",
"High", "High", "High", "Low", "Low", "Low", "High", "High",
"High", "Low", "High", "High", "Low", "Low", "High")), row.names = c(NA,
-50L), vars = c("Date", "Year", "Site", "Treatment", "Module #"
), labels = structure(list(Date = structure(c(17288, 17288, 17288,
17288, 17288, 17288, 17292, 17299, 17299, 17304, 17306, 17386,
17386, 17386, 17386, 17386, 17386, 17387, 17387, 17387, 17389,
17389, 17389, 17390, 17398, 17404, 17475, 17475, 17477, 17480,
17482, 17484, 17484, 17484, 17484, 17484, 17484, 17489, 17575,
17575, 17575, 17575, 17575, 17582, 17586, 17594, 17600, 17601,
17603, 17603), class = "Date"), Year = c(17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18), Site = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L), .Label = c("HAN", "WAI"), class = "factor"), Treatment = c("CLO",
"CLO", "CLO", "OPE", "OPE", "OPE", "CLO", "CLO", "OPE", "OPE",
"CLO", "CLO", "CLO", "CLO", "OPE", "OPE", "OPE", "CLO", "OPE",
"OPE", "CLO", "CLO", "OPE", "OPE", "CLO", "CLO", "CLO", "OPE",
"CLO", "OPE", "CLO", "CLO", "CLO", "CLO", "OPE", "OPE", "OPE",
"OPE", "CLO", "CLO", "CLO", "OPE", "OPE", "OPE", "CLO", "OPE",
"OPE", "CLO", "CLO", "OPE"), `Module #` = c(212L, 214L, 216L,
211L, 213L, 215L, 116L, 114L, 115L, 113L, 112L, 212L, 214L, 216L,
211L, 213L, 215L, 116L, 111L, 115L, 112L, 114L, 115L, 113L, 114L,
114L, 112L, 115L, 116L, 113L, 114L, 212L, 214L, 216L, 211L, 213L,
215L, 111L, 212L, 214L, 216L, 213L, 215L, 211L, 116L, 115L, 113L,
114L, 112L, 111L)), row.names = c(NA, -50L), class = "data.frame", vars = c("Date",
"Year", "Site", "Treatment", "Module #"), drop = TRUE), indices = list(
0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L,
26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L), drop = TRUE, group_sizes = 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), biggest_group_size = 1L, class = c("grouped_df", "tbl_df",
"tbl", "data.frame"))
Analyses
library(lme4)
library(gamlss)
recruitment_glmer_n3 <- glmer(recruits ~ Site_long*Shelter + (1|module_recruit), data = n3, family = poisson, na.action = "na.fail")
summary(recruitment_glmer_n3)
survival_gamlss <- gamlss(Survival_prop ~ Site_long*Treatment_long + (1|module_survival), data = survival_results_long_2, family = BEINF())
summary(survival_gamlss)
Table Code
library(sjPlot)
tab_model(recruitment_glmer_n3, survival_gamlss)
Is there a way to use sjPlot::tab_model to get html table outputs with gamlss model objects or is there another package that you would recommend for making publication-quality tables for linear model objects of gamlss as well as lmer and glmer? Thank you!
I have added (better) support for gamlss-models, so now you should be able to plot both models in one table with tab_model() (at least it worked for me). However, you need to update sjPlot and insight from GitHub first.
Then, it should work.

Error message with Lattice plot

I am trying to use xyplot in lattice to plot distributions, but keep getting the following:
Error in factor.levels[level] :
object of type 'builtin' is not subsettable
data
data<-structure(list(SAMS = 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, 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, 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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L, 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), .Label = "SURVEY", class = "factor"),
Totnum = c(159608.250877193, 159608.250877193, 159608.250877193,
159608.250877193, 159608.250877193, 159608.250877193, 159608.250877193,
159608.250877193, 159608.250877193, 159608.250877193, 159608.250877193,
159608.250877193, 159608.250877193, 159608.250877193, 159608.250877193,
159608.250877193, 159608.250877193, 159608.250877193, 159608.250877193,
159608.250877193, 159608.250877193, 159608.250877193, 159608.250877193,
159608.250877193, 159608.250877193, 159608.250877193, 159608.250877193,
159608.250877193, 159608.250877193, 159608.250877193, 159608.250877193,
159608.250877193, 73457.27, 73457.27, 73457.27, 73457.27,
73457.27, 73457.27, 73457.27, 73457.27, 73457.27, 73457.27,
73457.27, 73457.27, 73457.27, 73457.27, 73457.27, 73457.27,
73457.27, 73457.27, 73457.27, 73457.27, 73457.27, 73457.27,
73457.27, 73457.27, 73457.27, 73457.27, 73457.27, 73457.27,
73457.27, 73457.27, 73457.27, 61685.2133333333, 61685.2133333333,
61685.2133333333, 61685.2133333333, 61685.2133333333, 61685.2133333333,
61685.2133333333, 61685.2133333333, 61685.2133333333, 61685.2133333333,
61685.2133333333, 61685.2133333333, 61685.2133333333, 61685.2133333333,
61685.2133333333, 61685.2133333333, 61685.2133333333, 61685.2133333333,
61685.2133333333, 61685.2133333333, 61685.2133333333, 61685.2133333333,
61685.2133333333, 61685.2133333333, 61685.2133333333, 61685.2133333333,
61685.2133333333, 61685.2133333333, 61685.2133333333, 61685.2133333333,
61685.2133333333, 177260.582105263, 177260.582105263, 177260.582105263,
177260.582105263, 177260.582105263, 177260.582105263, 177260.582105263,
177260.582105263, 177260.582105263, 177260.582105263, 177260.582105263,
177260.582105263, 177260.582105263, 177260.582105263, 177260.582105263,
177260.582105263, 177260.582105263, 177260.582105263, 177260.582105263,
177260.582105263, 177260.582105263, 177260.582105263, 177260.582105263,
177260.582105263, 177260.582105263, 177260.582105263, 177260.582105263,
177260.582105263, 177260.582105263, 177260.582105263, 177260.582105263,
177260.582105263, 177260.582105263, 52880.77, 52880.77, 52880.77,
52880.77, 52880.77, 52880.77, 52880.77, 52880.77, 52880.77,
52880.77, 52880.77, 52880.77, 52880.77, 52880.77, 52880.77,
52880.77, 52880.77, 52880.77, 52880.77, 52880.77, 52880.77,
52880.77, 52880.77, 52880.77, 52880.77, 52880.77, 52880.77,
52880.77, 52880.77, 43688.205, 43688.205, 43688.205, 43688.205,
43688.205, 43688.205, 43688.205, 43688.205, 43688.205, 43688.205,
43688.205, 43688.205, 43688.205, 43688.205, 43688.205, 43688.205,
43688.205, 43688.205, 43688.205, 43688.205, 43688.205, 43688.205,
43688.205, 43688.205, 43688.205, 43688.205, 43688.205), Interval = c(2.5,
17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5,
67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 97.5, 102.5, 107.5, 112.5,
117.5, 122.5, 127.5, 132.5, 137.5, 142.5, 147.5, 152.5, 157.5,
162.5, 167.5, 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5,
42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5,
92.5, 97.5, 102.5, 107.5, 112.5, 117.5, 122.5, 127.5, 132.5,
137.5, 142.5, 147.5, 152.5, 2.5, 12.5, 17.5, 22.5, 27.5,
32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5,
82.5, 87.5, 92.5, 97.5, 102.5, 107.5, 112.5, 117.5, 122.5,
127.5, 132.5, 137.5, 142.5, 147.5, 152.5, 157.5, 7.5, 12.5,
17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5,
67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 97.5, 102.5, 107.5, 112.5,
117.5, 122.5, 127.5, 132.5, 137.5, 142.5, 147.5, 152.5, 157.5,
162.5, 167.5, 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5,
42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5,
92.5, 97.5, 102.5, 107.5, 112.5, 117.5, 122.5, 127.5, 132.5,
137.5, 142.5, 2.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5,
52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 97.5,
102.5, 107.5, 112.5, 117.5, 122.5, 127.5, 132.5, 137.5, 142.5
), Total_len = c(0, 115.15, 748.3, 2477.16666666667, 5497.5,
12447.2333333333, 21067.1464912281, 28781.0105263158, 27290.4377192982,
17257.9666666667, 6910.00526315789, 2230.81403508772, 616.9,
851.280701754386, 2293.05701754386, 5486.77543859649, 8042.88157894737,
5427.93245614035, 1601.13771929825, 638.890350877193, 938.466666666667,
1856.29035087719, 2176.17807017544, 2138.19210526316, 1501.78771929825,
755.716666666667, 224.966666666667, 138.05, 34.3, 24.05,
37.6666666666667, 1, 0, 1, 7, 6, 3.33, 30, 52.25, 222.26,
562.89, 1030.94333333333, 1609.71833333333, 2685.73, 4993.40666666667,
9019.255, 11521.7533333333, 13397.45, 11497.38, 7903.61166666667,
3746.61333333333, 1367.71833333333, 1049.31, 1017.63166666667,
573.103333333333, 262.931666666667, 193.696666666667, 280.306666666667,
214.07, 154.6, 24.18, 20.13, 9, 0, 5.8, 69.7, 134.4, 78.5,
37.4333333333333, 130.741666666667, 390.9, 760.083333333333,
1445.04166666667, 2070.96333333333, 3259.32333333333, 4837.90666666667,
6398.71, 8081.145, 8039.49, 8027.985, 6061.39833333333, 4682.04666666667,
2836.75833333333, 1763.26666666667, 1000.435, 512.731666666667,
461.376666666667, 247.441666666667, 184.66, 106.1, 40.8,
17.075, 2, 1, 4.75, 11, 50.35, 202.25, 847.673684210526,
3170.29070175439, 10974.9605263158, 23416.9806140351, 33056.3594736842,
32436.6875438597, 21245.1093859649, 9004.90289473684, 2252.90438596491,
907.376666666667, 1148.74035087719, 2320.57666666667, 3763.12166666667,
3288.86, 1750.43070175439, 2355.79035087719, 3885.26307017544,
5668.15236842105, 6339.69368421053, 4644.55, 2720.67736842105,
1198.01, 424.715, 117.88, 32.79, 8.13, 3.405, 7.2, 1, 0,
3, 3, 1, 4, 3, 35.5, 103.5, 229.57, 223.76, 206.63, 569.61,
1170.62, 3255.98, 7191.72, 10920.51, 10570.75, 7905.61, 3981.34,
1412.47, 1213.41, 1327.9, 934.87, 592.55, 522.73, 304.84,
137.21, 31.98, 23.71, 0, 18.73, 59.7, 30.15, 79.8, 553.725,
2103.605, 2761.8, 1332.71, 376.43, 77.6, 119.59, 299.49,
628.56, 1303.32, 2776.13, 5807.555, 8039.27, 8532.37, 5270.03,
2164.655, 701.405, 357.94, 174.385, 84.5, 31.18, 3.575),
fraction = c(0, 0.000721453930903607, 0.004688354116328,
0.0155202920466353, 0.0344437080776603, 0.0779861521251215,
0.131992841068334, 0.180322823965164, 0.170983878147354,
0.1081270333571, 0.0432935341699512, 0.0139768089859225,
0.00386508840620439, 0.00533356325300116, 0.0143667824497883,
0.0343765150513313, 0.0503913897605192, 0.0340078437443485,
0.0100316726140317, 0.00400286543688003, 0.00587981298904622,
0.0116302906690299, 0.0136344960753304, 0.0133965010800622,
0.00940921105923129, 0.00473482205658739, 0.00140949271375552,
0.000864930222850569, 0.000214901170907457, 0.000150681433245608,
0.000235994483115089, 0.00000626534025969264, 0, 0.0000136133564451823,
0.0000952934951162764, 0.0000816801386710941, 0.0000453324769624572,
0.00040840069335547, 0.000711297874260778, 0.00302570460350623,
0.00766282220942869, 0.0140345990714511, 0.0219136694480115,
0.0365617998055196, 0.0679770248290832, 0.122782333184993,
0.156849735000135, 0.182384262306508, 0.156517932125711,
0.107594682822635, 0.0510039827689395, 0.0186192371882774,
0.0142846310514943, 0.0138533826082383, 0.00780185995658882,
0.0035793824990592, 0.002636861765577, 0.00381591456729425,
0.00291421121422019, 0.00210462490642519, 0.000329170958844509,
0.000274036865241521, 0.000122520208006641, 0, 0.0000940257751668633,
0.00112993043605696, 0.00217880416938387, 0.00127259023286186,
0.000606844514439009, 0.00211949768188638, 0.00633701301943567,
0.0123219697600138, 0.0234260625615085, 0.0335730918549686,
0.0528380005062261, 0.0784289525031499, 0.103731666865166,
0.131006193596693, 0.130330910206249, 0.130144398733267,
0.0982633925666897, 0.0759022529656486, 0.045987655388401,
0.0285849164067629, 0.0162183924791484, 0.00831206765705709,
0.0074795342633167, 0.00401136112360585, 0.00299358614522638,
0.00172002323193176, 0.000661422694277245, 0.000276808639823136,
0.0000324226810920218, 0.0000162113405460109, 0.0000267967076694992,
0.0000620555335504192, 0.000284045101296692, 0.00114097560550657,
0.00478207661366671, 0.0178849164552092, 0.0619142755595742,
0.132104838740343, 0.186484547670357, 0.182988722922041,
0.119852418025734, 0.050800368518419, 0.0127095621553757,
0.00511888574374554, 0.00648051776223455, 0.0130913293813321,
0.0212293202581948, 0.0185538147338756, 0.00987490101276393,
0.0132899842869649, 0.0219183702548615, 0.0319763835879492,
0.0357648249199916, 0.0262018207592363, 0.0153484623378108,
0.00675846815897616, 0.00239599235744239, 0.000665009663174856,
0.000184981904101659, 0.0000458646807059008, 0.0000192090083399252,
0.0000406181674148199, 0.0000056414121409472, 0, 0.0000567313978219304,
0.0000567313978219304, 0.0000189104659406435, 0.0000756418637625738,
0.0000567313978219304, 0.000671321540892843, 0.0019572332248566,
0.00434127566599352, 0.00423140585887838, 0.00390746957731516,
0.0107715905044499, 0.022136969639436, 0.0615720988934163,
0.135998776114644, 0.206511932409456, 0.199897807842057,
0.14949876864501, 0.0752889944681214, 0.0267104658271807,
0.0229461484770362, 0.0251112077225804, 0.0176788272939293,
0.0112053965931283, 0.00988506786115255, 0.00576466643734575,
0.00259470503171569, 0.000604756700781778, 0.000448367147452656,
0, 0.000428719834106254, 0.00136650155345133, 0.000690117618702805,
0.00182657996591986, 0.0126744735793105, 0.0481504103910884,
0.0632161472415724, 0.0305050299045246, 0.00861628441818564,
0.00177622312475415, 0.00273735210682151, 0.0068551683457812,
0.0143874073105086, 0.0298323082854972, 0.0635441533933472,
0.132931874861876, 0.184014655671937, 0.195301454935033,
0.120628210749332, 0.0495478127334369, 0.0160547909899251,
0.0081930580576611, 0.00399158079394656, 0.00193416049022843,
0.000713693776157661, 0.0000818298668942796)), .Names = c("SAMS",
"Year", "Gear", "Totnum", "Interval", "Total_len", "fraction"
), row.names = c(51L, 58L, 44L, 55L, 38L, 43L, 60L, 40L, 54L,
47L, 62L, 48L, 32L, 35L, 37L, 56L, 63L, 49L, 52L, 57L, 59L, 50L,
34L, 33L, 41L, 53L, 61L, 46L, 39L, 36L, 42L, 45L, 98L, 110L,
93L, 106L, 115L, 102L, 101L, 99L, 95L, 100L, 120L, 111L, 119L,
121L, 107L, 94L, 92L, 97L, 103L, 113L, 114L, 112L, 116L, 109L,
118L, 96L, 105L, 104L, 117L, 122L, 108L, 151L, 149L, 176L, 155L,
177L, 179L, 150L, 153L, 175L, 165L, 162L, 161L, 159L, 172L, 152L,
156L, 154L, 166L, 178L, 174L, 163L, 171L, 160L, 173L, 158L, 157L,
168L, 167L, 164L, 170L, 169L, 239L, 218L, 240L, 227L, 237L, 231L,
224L, 238L, 234L, 243L, 230L, 220L, 222L, 211L, 217L, 219L, 221L,
226L, 214L, 223L, 235L, 242L, 228L, 216L, 213L, 215L, 236L, 241L,
229L, 225L, 212L, 232L, 233L, 277L, 279L, 271L, 295L, 276L, 272L,
275L, 281L, 289L, 298L, 288L, 285L, 284L, 282L, 291L, 270L, 274L,
273L, 290L, 296L, 297L, 286L, 294L, 287L, 292L, 280L, 293L, 283L,
278L, 344L, 345L, 325L, 333L, 341L, 339L, 337L, 336L, 348L, 332L,
334L, 329L, 328L, 323L, 322L, 324L, 326L, 335L, 347L, 346L, 331L,
343L, 342L, 340L, 330L, 338L, 327L), class = "data.frame")
lattice plot
xyplot(fraction~Interval|Year, data=data,type="l",
groups=SAMS,
ylab=list("Fraction of Total",cex=1.2),
xlab=list("Length Interval (mm)",cex=1.2),
scales=list(relation="same",
y=list(alternating=1,cex=1.2),
x=list(alternating=1,cex=1.2,
abbreviate=F)),
strip = strip.custom(factor.levels=names,bg="white", strip.levels = T),
drop.unused.levels=T,
as.table=T,
par.strip.text=list(cex=1.5))
I can use the xyplot function if I add subset = Year== 2015, etc., but I haven't had this type of problem before with lattice.
R session info
R version 3.3.2 (2016-10-31)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

annotation_logticks and facet plots in ggplot2

This should be very simple. If I produce facet plots and I want to add the annotation_logticks, ticks appear in all the plots.
What if I want to have the ticks on only the first "columns" of the faceting? Is it possible?
For example, using the CO2 dataset:
structure(list(Plant = 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, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L,
11L, 11L), .Label = c("Qn1", "Qn2", "Qn3", "Qc1", "Qc3", "Qc2",
"Mn3", "Mn2", "Mn1", "Mc2", "Mc3", "Mc1"), class = c("ordered",
"factor")), Type = 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, 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("Quebec",
"Mississippi"), class = "factor"), Treatment = structure(c(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, 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), .Label = c("nonchilled", "chilled"), class = "factor"),
conc = c(95, 175, 250, 350, 500, 675, 1000, 95, 175, 250,
350, 500, 675, 1000, 95, 175, 250, 350, 500, 675, 1000, 95,
175, 250, 350, 500, 675, 1000, 95, 175, 250, 350, 500, 675,
1000, 95, 175, 250, 350, 500, 675, 1000, 95, 175, 250, 350,
500, 675, 1000, 95, 175, 250, 350, 500, 675, 1000, 95, 175,
250, 350, 500, 675, 1000, 95, 175, 250, 350, 500, 675, 1000,
95, 175, 250, 350, 500, 675, 1000, 95, 175, 250, 350, 500,
675, 1000), uptake = c(16, 30.4, 34.8, 37.2, 35.3, 39.2,
39.7, 13.6, 27.3, 37.1, 41.8, 40.6, 41.4, 44.3, 16.2, 32.4,
40.3, 42.1, 42.9, 43.9, 45.5, 14.2, 24.1, 30.3, 34.6, 32.5,
35.4, 38.7, 9.3, 27.3, 35, 38.8, 38.6, 37.5, 42.4, 15.1,
21, 38.1, 34, 38.9, 39.6, 41.4, 10.6, 19.2, 26.2, 30, 30.9,
32.4, 35.5, 12, 22, 30.6, 31.8, 32.4, 31.1, 31.5, 11.3, 19.4,
25.8, 27.9, 28.5, 28.1, 27.8, 10.5, 14.9, 18.1, 18.9, 19.5,
22.2, 21.9, 7.7, 11.4, 12.3, 13, 12.5, 13.7, 14.4, 10.6,
18, 17.9, 17.9, 17.9, 18.9, 19.9)), .Names = c("Plant", "Type",
"Treatment", "conc", "uptake"), row.names = 1:84, class = c("nfnGroupedData",
"nfGroupedData", "groupedData", "data.frame"), formula = uptake ~
conc | Plant, outer = ~Treatment * Type, labels = structure(list(
x = "Ambient carbon dioxide concentration", y = "CO2 uptake rate"), .Names = c("x",
"y")), units = structure(list(x = "(uL/L)", y = "(umol/m^2 s)"), .Names = c("x",
"y")))
With this small piece of code:
ggplot(data, aes(conc, uptake))+
geom_point()+
scale_y_log10(breaks=c(1,10,100))+
facet_grid(~Type)+
annotation_logticks(sides="l")
Given the example plot
p <- ggplot(mtcars, aes(disp, hp)) +
facet_wrap(~vs) +
geom_point() +
scale_y_log10()
you can use the following "hack" to have the ticks only for facets identified by vs=c(0)
a <- annotation_logticks(sides='l')
a$data <- data.frame(x=NA, vs=c(0))
p + a
Unfortunately, it provokes a warning.

Resources