Skip to content

Commit 86dd79a

Browse files
authored
Merge pull request #4 from teunbrand/ggplot2_360
Compatibility with ggplot2 3.6.0
2 parents 4f6c899 + 901ee95 commit 86dd79a

File tree

2 files changed

+133
-109
lines changed

2 files changed

+133
-109
lines changed

Diff for: R/hello.R

+98-79
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,11 @@ plot_design.factorial_rcbd <- function(design,
276276
min(table$col)
277277
}
278278

279-
plt <- ggplot(table, aes_string(x = "col", y = y)) +
280-
geom_tile(aes_string(fill = factor_name),
279+
plt <- ggplot(table, aes(x = .data[["col"]], y = .data[[y]])) +
280+
geom_tile(aes(fill = .data[[factor_name]]),
281281
width = width * space_width, height = height *
282282
space_height) + theme_bw() + theme(line = element_blank()) +
283-
geom_text(aes_string(label = "plots"),
283+
geom_text(aes(label = .data[["plots"]]),
284284
colour = "black")
285285

286286
return(plt)
@@ -367,11 +367,11 @@ plot_design_crd <- function(design,
367367
table$col <- abs(table$col - max(table$col)) +
368368
min(table$col)
369369
}
370-
plt <- ggplot(table, aes_string(x = "col", y)) +
371-
geom_tile(aes_string(fill = factor_name),
370+
plt <- ggplot(table, aes(x = .data$col, .data[[y]])) +
371+
geom_tile(aes(fill = .data[[factor_name]]),
372372
width = width * space_width, height = height *
373373
space_height) + theme_bw() + theme(line = element_blank()) +
374-
geom_text(aes_string(label = labels), colour = "black")
374+
geom_text(aes(label = .data[[labels]]), colour = "black")
375375

376376
plt
377377

@@ -461,11 +461,11 @@ plot_alpha <- function(design, x = "cols", y = "block",
461461
table[, y] <- abs(table[, y] - max(table[, y])) +
462462
min(table[, y])
463463
}
464-
plt <- ggplot(table, aes_string(x, y)) +
465-
geom_tile(aes_string(fill = factor_name),
464+
plt <- ggplot(table, aes(.data[[x]], .data[[y]])) +
465+
geom_tile(aes(fill = .data[[factor_name]]),
466466
width = width * space_width, height = height *
467467
space_height) + theme_bw() + theme(line = element_blank())+
468-
geom_text(aes_string(label = labels), colour = "black")
468+
geom_text(aes(label = .data[[labels]]), colour = "black")
469469

470470
plt
471471

@@ -555,11 +555,11 @@ plot_lattice_triple <- function(design,
555555
min(table[, y])
556556
}
557557

558-
plt <- ggplot(table, aes_string(x = "part", y)) +
559-
geom_tile(aes_string(fill = factor_name),
558+
plt <- ggplot(table, aes(x = .data[["part"]], .data[[y]])) +
559+
geom_tile(aes(fill = .data[[factor_name]]),
560560
width = width * space_width, height = height *
561561
space_height) + theme_bw() + theme(line = element_blank())+
562-
geom_text(aes_string(label = labels), colour = "black")
562+
geom_text(aes(label = .data[[labels]]), colour = "black")
563563

564564
plt
565565

@@ -647,12 +647,12 @@ plot_lattice_simple <- function(design,
647647
min(table[, y])
648648
}
649649

650-
plt <- ggplot(table, aes_string(x = "part", y)) +
651-
geom_tile(aes_string(fill = factor_name),
650+
plt <- ggplot(table, aes(x = .data[["part"]], .data[[y]])) +
651+
geom_tile(aes(fill = .data[[factor_name]]),
652652
width = width * space_width, height = height *
653653
space_height) +
654654
theme_bw() + theme(line = element_blank()) +
655-
geom_text(aes_string(label = labels), colour = "black")
655+
geom_text(aes(label = .data[[labels]]), colour = "black")
656656

657657
plt
658658

@@ -736,11 +736,11 @@ plot_latin_square <- function(design,
736736
table[, x] <- abs(table[, x] - max(table[, x] )) +
737737
min(table[, x] )
738738
}
739-
plt <- ggplot(table, aes_string(x = x, y = y)) +
740-
geom_tile(aes_string(fill = factor_name),
739+
plt <- ggplot(table, aes(x = .data[[x]], y = .data[[y]])) +
740+
geom_tile(aes(fill = .data[[factor_name]]),
741741
width = width * space_width, height = height *
742742
space_height) + theme_bw() + theme(line = element_blank()) +
743-
geom_text(aes_string(label = labels), colour = "black")
743+
geom_text(aes(label = .data[[labels]]), colour = "black")
744744

745745
plt
746746

@@ -827,12 +827,12 @@ plot_graeco <- function(design,
827827
table[, x] <- abs(table[, x] - max(table[, x] )) +
828828
min(table[, x] )
829829
}
830-
plt <- ggplot(table, aes_string(x, y)) +
831-
geom_tile(aes_string(fill = factor_name),
830+
plt <- ggplot(table, aes(.data[[x]], .data[[y]])) +
831+
geom_tile(aes(fill = .data[[factor_name]]),
832832
width = width * space_width,
833833
height = height *space_height) +
834834
theme_bw() + theme(line = element_blank()) +
835-
geom_text(aes_string(label = labels), colour = "black")
835+
geom_text(aes(label = .data[[labels]]), colour = "black")
836836

837837

838838
return(plt)
@@ -940,11 +940,11 @@ plot_strip <- function(design,
940940
table[, x] <- abs(table[, x] - max(table[, x] )) +
941941
min(table[, x] )
942942
}
943-
plt <- ggplot(table, aes_string(x = x, y = y)) +
944-
geom_tile(aes_string(fill = factor_name_1),
943+
plt <- ggplot(table, aes(x = .data[[x]], y = .data[[y]])) +
944+
geom_tile(aes(fill = .data[[factor_name_1]]),
945945
width = width * space_width, height = height *
946946
space_height) + theme_bw() + theme(line = element_blank()) +
947-
geom_text(aes_string(label = labels), colour = "black")
947+
geom_text(aes(label = .data[[labels]]), colour = "black")
948948

949949

950950
return(plt)
@@ -1031,11 +1031,11 @@ plot_bib <- function(design,
10311031
table$col <- abs(table$col - max(table$col)) +
10321032
min(table$col)
10331033
}
1034-
plt <- ggplot(table, aes_string(x = "col", y = y)) +
1035-
geom_tile(aes_string(fill = factor_name),
1034+
plt <- ggplot(table, aes(x = .data[["col"]], y = .data[[y]])) +
1035+
geom_tile(aes(fill = .data[[factor_name]]),
10361036
width = width * space_width, height = height *
10371037
space_height) + theme_bw() + theme(line = element_blank()) +
1038-
geom_text(aes_string(label = labels), colour = "black")
1038+
geom_text(aes(label = .data[[labels]]), colour = "black")
10391039

10401040

10411041
return(plt)
@@ -1122,11 +1122,11 @@ plot_cyclic <- function(design,
11221122
table$part <- abs(table$part - max(table$part)) +
11231123
min(table$part)
11241124
}
1125-
plt <- ggplot(table, aes_string(x = "part", y = y)) +
1126-
geom_tile(aes_string(fill = factor_name),
1125+
plt <- ggplot(table, aes(x = .data[["part"]], y = .data[[y]])) +
1126+
geom_tile(aes(fill = .data[[factor_name]]),
11271127
width = width * space_width, height = height *
11281128
space_height) + theme_bw() + theme(line = element_blank()) +
1129-
geom_text(aes_string(label = labels), colour = "black")
1129+
geom_text(aes(label = .data[[labels]]), colour = "black")
11301130

11311131

11321132
return(plt)
@@ -1219,11 +1219,11 @@ plot_dau <- function(design,
12191219
table$col <- abs(table$col - max(table$col)) +
12201220
min(table$col)
12211221
}
1222-
plt <- ggplot(table, aes_string(x = "col", y = y)) +
1223-
geom_tile(aes_string(fill = factor_name),
1222+
plt <- ggplot(table, aes(x = .data[["col"]], y = .data[[y]])) +
1223+
geom_tile(aes(fill = .data[[factor_name]]),
12241224
width = width * space_width, height = height *
12251225
space_height) + theme_bw() + theme(line = element_blank()) +
1226-
geom_text(aes_string(label = labels), colour = "black")
1226+
geom_text(aes(label = .data[[labels]]), colour = "black")
12271227

12281228

12291229
return(plt)
@@ -1318,11 +1318,11 @@ plot_rcbd <- function(design,
13181318
table[, y] <- as.numeric(table[, y]) * height
13191319
table[, labels] <- str_wrap(table[,treatment_label], width = label_width)
13201320

1321-
plt <- ggplot(table, aes_string(x = "col", y = y)) +
1322-
geom_tile(aes_string(fill = factor_name),
1321+
plt <- ggplot(table, aes(x = .data[["col"]], y = .data[[y]])) +
1322+
geom_tile(aes(fill = .data[[factor_name]]),
13231323
width = width * space_width, height = height *
13241324
space_height) + theme_bw() + theme(line = element_blank()) +
1325-
geom_label(aes_string(label = labels), colour = "black",fill= "white")
1325+
geom_label(aes(label = .data[[labels]]), colour = "black",fill= "white")
13261326

13271327

13281328
return(plt)
@@ -1431,12 +1431,12 @@ plot_design.factorial_crd <- function(design,
14311431
table$col <- abs(table$col - max(table$col)) +
14321432
min(table$col)
14331433
}
1434-
plt <- ggplot(table, aes_string(x = "col", y = y)) +
1435-
geom_tile(aes_string(fill = factor_name),
1434+
plt <- ggplot(table, aes(x = .data[["col"]], y = .data[[y]])) +
1435+
geom_tile(aes(fill = .data[[factor_name]]),
14361436
width = width * space_width, height = height *
14371437
space_height) + theme_bw() +
14381438
theme(line = element_blank()) +
1439-
geom_text(aes_string(label = labels),
1439+
geom_text(aes(label = .data[[labels]]),
14401440
colour = "black")
14411441

14421442
return(plt)
@@ -1525,13 +1525,12 @@ plot_design.factorial_lsd <- function(design,
15251525
table[, x] <- abs(table[, x] - max(table[, x] )) +
15261526
min(table[, x] )
15271527
}
1528-
plt <- ggplot(table, aes_string(x = x,
1529-
y = y)) +
1530-
geom_tile(aes_string(fill = factor_name),
1528+
plt <- ggplot(table, aes(x = .data[[x]], y = .data[[y]])) +
1529+
geom_tile(aes(fill = .data[[factor_name]]),
15311530
width = width * space_width, height = height *
15321531
space_height) + theme_bw() +
15331532
theme(line = element_blank()) +
1534-
geom_text(aes_string(label = labels),
1533+
geom_text(aes(label = .data[[labels]]),
15351534
colour = "black")
15361535

15371536
plt
@@ -1649,23 +1648,23 @@ plot_split_rcbd <- function(design,
16491648
divider <- length(unique(table[, factor_name_1]))
16501649
table$sequence <- table$sequence/divider
16511650

1652-
plt2 <- ggplot(table, aes_string("sequence", y)) +
1653-
geom_tile(aes_string(fill = factor_name_2),
1651+
plt2 <- ggplot(table, aes(.data[["sequence"]], .data[[y]])) +
1652+
geom_tile(aes(fill = .data[[factor_name_2]]),
16541653
width = width/divider * space_width,
16551654
height = height * space_height) + theme_bw() +
1656-
theme(line = element_blank()) + geom_text(aes_string(label = labels),
1655+
theme(line = element_blank()) + geom_text(aes(label = .data[[labels]]),
16571656
colour = "black")
16581657

16591658

16601659
return(plt2)
16611660

16621661
} else{
16631662

1664-
plt <- ggplot(table, aes_string("row", y)) +
1665-
geom_tile(aes_string(fill = factor_name_1),
1663+
plt <- ggplot(table, aes(.data[["row"]], .data[[y]])) +
1664+
geom_tile(aes(fill = .data[[factor_name_1]]),
16661665
width = width * space_width, height = height * space_height) +
16671666
theme_bw() + theme(line = element_blank()) +
1668-
geom_text(aes_string(label = labels), colour = "black")
1667+
geom_text(aes(label = .data[[labels]]), colour = "black")
16691668
return(plt)
16701669
}
16711670

@@ -1774,22 +1773,22 @@ plot_split_lsd <- function(design,
17741773
divider <- length(unique(table[, factor_name_1]))
17751774
table$sequence <- table$sequence/divider
17761775

1777-
plt2 <- ggplot(table, aes_string("sequence", "row")) +
1778-
geom_tile(aes_string(fill = factor_name_2),
1776+
plt2 <- ggplot(table, aes(.data[["sequence"]], .data[["row"]])) +
1777+
geom_tile(aes(fill = .data[[factor_name_2]]),
17791778
width = width/divider * space_width,
17801779
height = height * space_height) + theme_bw() +
17811780
theme(line = element_blank()) +
1782-
geom_text(aes_string(label = labels),colour = "black")
1781+
geom_text(aes(label = .data[[labels]]),colour = "black")
17831782

17841783

17851784
return(plt2)
17861785
} else {
1787-
plt <- ggplot(table, aes_string("col", "row")) +
1788-
geom_tile(aes_string(fill = factor_name_1),
1786+
plt <- ggplot(table, aes(.data[["col"]], .data[["row"]])) +
1787+
geom_tile(aes(fill = .data[[factor_name_1]]),
17891788
width = width * space_width, height = height *
17901789
space_height) + theme_bw() +
17911790
theme(line = element_blank()) +
1792-
geom_text(aes_string(label = labels),
1791+
geom_text(aes(label = .data[[labels]]),
17931792
colour = "black")
17941793

17951794
return(plt)
@@ -1936,22 +1935,22 @@ plot_split_crd <- function(design, nrows, ncols,
19361935
divider <- length(unique(table[, factor_name_1]))
19371936
table$sequence <- table$sequence/divider
19381937

1939-
plt2 <- ggplot(table, aes_string("sequence", "row")) +
1940-
geom_tile(aes_string(fill = factor_name_2),
1938+
plt2 <- ggplot(table, aes(.data[["sequence"]], .data[["row"]])) +
1939+
geom_tile(aes(fill = .data[[factor_name_2]]),
19411940
width = width * space_width/divider,
19421941
height = height * space_height) +
19431942
theme_bw() + theme(line = element_blank()) +
1944-
geom_text(aes_string(label = labels),
1943+
geom_text(aes(label = .data[[labels]]),
19451944
colour = "black")
19461945

19471946
return(plt2)
19481947
} else {
1949-
plt <- ggplot(table, aes_string("col", "row")) +
1950-
geom_tile(aes_string(fill = factor_name_1),
1948+
plt <- ggplot(table, aes(.data[["col"]], .data[["row"]])) +
1949+
geom_tile(aes(fill = .data[[factor_name_1]]),
19511950
width = width * space_width, height = height *
19521951
space_height) + theme_bw() +
19531952
theme(line = element_blank()) +
1954-
geom_text(aes_string(label = labels),
1953+
geom_text(aes(label = .data[[labels]]),
19551954
colour = "black")
19561955

19571956
return(plt)
@@ -1993,15 +1992,26 @@ plot_split_crd <- function(design, nrows, ncols,
19931992
#' plot_split_crd(outdesign2,ncols = 6,nrows=5)+
19941993
#' theme_pres()
19951994
theme_pres <- function() {
1996-
theme(text = element_text(size = 16, colour = "black"),
1997-
axis.text = element_text(size = 18, colour = "black"),
1998-
axis.title = element_text(size = 18, colour = "black"),
1999-
axis.line = element_line(colour = "black",
2000-
size = 1, linetype = "solid"),
2001-
axis.ticks = element_line(colour = "black")) +
2002-
theme(plot.background = element_rect(fill = "white",
2003-
color = NA),
2004-
panel.background = element_rect(fill = "white",color = NA))
1995+
my_theme <- theme(text = element_text(size = 16, colour = "black"),
1996+
axis.text = element_text(size = 18, colour = "black"),
1997+
axis.title = element_text(size = 18, colour = "black"),
1998+
axis.line = element_line(colour = "black",
1999+
linewidth = 1, linetype = "solid"),
2000+
axis.ticks = element_line(colour = "black"),
2001+
plot.background = element_rect(fill = "white",
2002+
color = NA),
2003+
panel.background = element_rect(fill = "white",color = NA))
2004+
2005+
if (packageVersion("ggplot2") >= "3.4.0") {
2006+
my_theme <- my_theme +
2007+
theme(axis.line = element_line(colour = "black",
2008+
linewidth = 1, linetype = "solid"))
2009+
} else {
2010+
my_theme <- my_theme +
2011+
theme(axis.line = element_line(colour = "black",
2012+
size = 1, linetype = "solid"))
2013+
}
2014+
my_theme
20052015
}
20062016

20072017

@@ -2023,15 +2033,24 @@ theme_pres <- function() {
20232033
#' plot_split_crd(outdesign2,ncols = 6,nrows=5)+
20242034
#' theme_poster()
20252035
theme_poster <- function() {
2026-
theme(text = element_text(size = 24, colour = "black"),
2036+
my_theme <- theme(text = element_text(size = 24, colour = "black"),
20272037
axis.text = element_text(size = 28, colour = "black"),
20282038
axis.title = element_text(size = 28, colour = "black"),
2029-
axis.line = element_line(colour = "black",
2030-
size = 1, linetype = "solid"),
20312039
axis.ticks = element_line(colour = "black")) +
20322040
theme(plot.background = element_rect(fill = "white",
20332041
color = NA),
20342042
panel.background = element_rect(fill = "white", color = NA))
2043+
2044+
if (packageVersion("ggplot2") >= "3.4.0") {
2045+
my_theme <- my_theme +
2046+
theme(axis.line = element_line(colour = "black",
2047+
linewidth = 1, linetype = "solid"))
2048+
} else {
2049+
my_theme <- my_theme +
2050+
theme(axis.line = element_line(colour = "black",
2051+
size = 1, linetype = "solid"))
2052+
}
2053+
my_theme
20352054
}
20362055

20372056

@@ -2097,11 +2116,11 @@ plot_youden <- function(design, x = "col", y = "row",
20972116
}
20982117

20992118

2100-
plt <- ggplot(table, aes_string(x = x, y = y)) +
2101-
geom_tile(aes_string(fill = factor_name),
2119+
plt <- ggplot(table, aes(x = .data[[x]], y = .data[[y]])) +
2120+
geom_tile(aes(fill = .data[[factor_name]]),
21022121
width = width * space_width, height = height *
21032122
space_height) + theme_bw() + theme(line = element_blank()) +
2104-
geom_text(aes_string(label = labels), colour = "black")
2123+
geom_text(aes(label = .data[[labels]]), colour = "black")
21052124

21062125

21072126
return(plt)
@@ -2884,11 +2903,11 @@ full_control_positions <- function(design,
28842903
table[, x] <- abs(table[, x] - max(table[, x] )) +
28852904
min(table[, x] )
28862905
}
2887-
plt <- ggplot(table, aes_string(x = x, y = y)) +
2888-
geom_tile(aes_string(fill = factor_name),
2906+
plt <- ggplot(table, aes(x = .data[[x]], y = .data[[y]])) +
2907+
geom_tile(aes(fill = .data[[factor_name]]),
28892908
width = width * space_width, height = height *
28902909
space_height) + theme_bw() + theme(line = element_blank()) +
2891-
geom_text(aes_string(label = labels), colour = "black")
2910+
geom_text(aes(label = .data[[labels]]), colour = "black")
28922911

28932912
plt
28942913

0 commit comments

Comments
 (0)