Comments (6)
Dear Steve,
For me to see and reproduce the error I would need a minimal reproducible example. See https://www.tidyverse.org/help/#reprex for instructions.
Without it, I can't understand or reproduce your issue.
Best,
Sergio
from facetscales.
Glad to! My use case is hard to simplify, but there is a nice example in https://stackoverflow.com/questions/56411786/adjust-x-and-y-scales-for-individual-facets-in-facet-grid-to-fit-geom-text-rep. I haven't tried to simplify plotdat from the author's example because of its complex structure.
devtools::install_github("zeehio/facetscales")
library(facetscales)
library(scales)
library(ggrepel)
library(forcats)
library(RColorBrewer)
library(tidyverse)
ylimits <-
c(2, NA) #keep the labels above the cluster of points at the bottom of the facets
plotdat <- dput(
structure(
list(
SpeciesOrTaxon = c(
"Squatina argentina", "Dipturus batis", "Squatina squatina", "Thunnus maccoyii", "Epinephelus striatus",
"Sphyrna lewini", "Mobula mobular", "Isurus oxyrinchus", "Mustelus schmitti",
"Pseudotolithus senegalensis", "Sebastolobus alascanus", "Leucoraja circularis",
"Argyrosomus hololepidotus", "Raja undulata", "Isurus paucus",
"Thunnus thynnus", "Hippoglossus hippoglossus", "Merluccius senegalensis",
"Apostichopus japonicus", "Carcharhinus falciformis", "Carcharhinus longimanus",
"Lamna nasus", "Sphyrna zygaena", "Alopias vulpinus", "Cetorhinus maximus",
"Alopias superciliosus", "Carcharodon carcharias", "Sardinella maderensis",
"Galeorhinus galeus", "Pomatomus saltatrix", "Pentanemus quinquarius",
"Pseudupeneus prayensis", "Nemipterus virgatus", "Pseudotolithus senegallus",
"Dalatias licha", "Lutjanus campechanus", "Megalops atlanticus",
"Mola mola", "Mustelus mustelus", "Centrophorus squamosus", "Balistes capriscus",
"Centrophorus lusitanicus", "Leucoraja fullonica", "Rhomboplites aurorubens",
"Dentex dentex", "Epinephelus marginatus", "Palinurus elephas",
"Alosa immaculata", "Carcharhinus plumbeus", "Oxynotus centrina",
"Gymnura altavela", "Carcharias taurus", "Gadus morhua", "Melanogrammus aeglefinus",
"Thunnus obesus", "Trachurus trachurus", "Squalus acanthias",
"Makaira nigricans", "Thunnus orientalis"
),
Name_abbrev = c(
"S. argentina", "D. batis", "S. squatina", "T. maccoyii", "E. striatus", "S. lewini",
"M. mobular", "I. oxyrinchus", "M. schmitti", "P. senegalensis",
"S. alascanus", "L. circularis", "A. hololepidotus", "R. undulata",
"I. paucus", "T. thynnus", "H. hippoglossus", "M. senegalensis",
"A. japonicus", "C. falciformis", "C. longimanus", "L. nasus",
"S. zygaena", "A. vulpinus", "C. maximus", "A. superciliosus",
"C.carcharias", "S. maderensis", "G. galeus", "P. saltatrix",
"P. quinquarius", "P. prayensis", "N. virgatus", "P. senegallus",
"D. licha", "L. campechanus", "M. atlanticus", "M. mola", "M. mustelus",
"C. squamosus", "B. capriscus", "C. lusitanicus", "L. fullonica",
"R. aurorubens", "D. dentex", "E. marginatus", "P. elephas",
"A. immaculata", "C. plumbeus", "O. centrina", "G. altavela",
"C. taurus", "G. morhua", "M. aeglefinus", "T. obesus", "T. trachurus",
"S. acanthias", "M. nigricans", "T. orientalis"),
redlistCategory = structure(
c(
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L
),
.Label = c("CR", "EN", "VU"),
class = "factor"
),
TaxonGroup = structure(
c(
2L, 2L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 3L, 3L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 2L,
3L, 3L, 3L, 2L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 1L, 3L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 2L, 3L, 3L
),
.Label = c("Invertebrates", "Cartilaginous fish", "Bony fish"),
class = "factor"
),
totRank = c(
12, 39, 55, 7, 38, 56, 57, 8, 11, 17, 33, 36, 37, 50, 58, 6, 9, 16,
51, 15, 27, 30, 43, 45, 49, 52, 53, 5, 13, 14, 19, 20, 22, 23,
24, 25, 26, 28, 29, 31, 32, 34, 35, 40, 41, 42, 44, 46, 47, 48,
54, 59, 1, 2, 3, 4, 10, 18, 21),
VARIABLE = structure(
c(
3L, 3L, 3L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("CITES", "YES", "NO"),
class = "factor"
),
catch_ema_thousands = c(
3.886654422, 0.1724791016, 0.00911430205, 10.54412869, 0.174470439, 0.00807692997,
0.001640665002, 9.424452066, 6.583041893, 2.659608617, 0.2663195953,
0.2329239555, 0.2219422872, 0.01671489332, 0.0014159872, 13.44830652,
7.585155675, 2.774650025, 0.01599999, 3.024126379, 0.4539170316,
0.3113769576, 0.1163730191, 0.1011488649, 0.01681304105, 0.01561369792,
0.01416268544, 108.778465, 3.822553738, 3.251341729, 2.440669803,
1.688880545, 1.358903072, 1.100693581, 1.06694699, 0.8025907339,
0.5465603847, 0.4392502858, 0.3591757093, 0.2919081194, 0.2671983104,
0.2478545144, 0.2435067011, 0.15794176, 0.1539382418, 0.1226202735,
0.1079683714, 0.06792588753, 0.03801280875, 0.02357907878, 0.009323075655,
0.000514006594, 1652.737638, 484.1897672, 397.4311939, 153.0306153,
7.422144444, 2.459107988, 1.545317165)),
row.names = c(NA, -59L),
class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame")
)
)
special.points <- special.points <- rownames(subset(
plotdat,
SpeciesOrTaxon %in% c(
"Gadus morhua", "Melanogrammus aeglefinus", "Thunnus obesus", "Trachurus trachurus",
"Sardinella maderensis", "Thunnus thynnus", "Thunnus maccoyii", "Hippoglossus hippoglossus",
"Squalus acanthias", "Merluccius senegalensis", "Epinephelus striatus", "Apostichopus japonicus",
"Mobula mobular", "Isurus oxyrinchus", "Mustelus schmitti", "Pseudotolithus senegalensis",
"Sebastolobus alascanus", "Leucoraja circularis", "Argyrosomus hololepidotus",
"Raja undulata", "Isurus paucus", "Sphyrna lewini", "Squatina argentina", "Dipturus batis",
"Squatina squatina", "Carcharhinus falciformis", "Squalus acanthias", "Makaira nigricans",
"Thunnus orientalis", "Carcharhinus longimanus", "Lamna nasus", "Sphyrna zygaena",
"Alopias vulpinus", "Cetorhinus maximus", "Alopias superciliosus", "Carcharodon carcharias",
"Palinurus elephas"
)
))
p <-
ggplot(data = plotdat,
aes(
x = -totRank,
y = catch_ema_thousands,
label = Name_abbrev
)) +
geom_point(
data = plotdat,
aes(color = VARIABLE),
size = 1.2,
shape = 1,
stroke = 0.8
) +
scale_color_manual(
values = c("black", "orange", "darkgrey"),
labels = c("CITES", "Intl trade", "No intl trade")
) +
facet_grid(redlistCategory ~ TaxonGroup,
scales = "free",
space = "free") +
scale_y_sqrt() +
geom_text_repel(
data = plotdat,
aes(
x = -totRank,
y = catch_ema_thousands,
label = Name_abbrev
),
# used the abbreviated species name to try and fit them better
segment.color = "black",
segment.size = 0.2,
segment.alpha = 0.5,
direction = "both",
min.segment.length = 0.5,
force = 10,
size = 2,
color = "black",
ylim = ylimits
) +
ylab("Average catch (thousand tonnes)") +
theme(
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
legend.position = "top",
legend.title = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black")
)
scales_y <- list(
CR = scale_y_sqrt(limits = c(0, 50), breaks = c(0, 50, 10)),
EN = scale_y_continuous(limits = c(0, 50), breaks = c(0, 50, 10)),
VU = scale_y_continuous(labels = scientific_format())
)
scales_x <- list(
'Invertebrates' = scale_x_discrete(limits = c(-50, -40)),
# plotting in reverse rank (-59 to 0)
'Cartilaginous fish' = scale_x_discrete(limits = c(-59, 0)),
'Bony fish' = scale_x_discrete(limits = c(-59, 0))
)
print (p)
p <- p +
facet_grid(redlistCategory ~ TaxonGroup, scales = list(y = scales_y, x = scales_x))
from facetscales.
Your code does not use facetscales
(you should be using facet_grid_sc
instead of facet_grid
).
If I change facet_grid
with facet_grid_sc
I get a different error I am discussing on #9
from facetscales.
Here is your reproducible example once I installed this branch:
devtools::install_github("zeehio/facetscales@fix-panel-without-data")
Does this plot meet your expectations?
library(facetscales)
library(scales)
library(ggrepel)
#> Loading required package: ggplot2
library(forcats)
library(RColorBrewer)
library(tidyverse)
ylimits <-
c(2, NA) #keep the labels above the cluster of points at the bottom of the facets
plotdat <- dput(
structure(
list(
SpeciesOrTaxon = c(
"Squatina argentina", "Dipturus batis", "Squatina squatina", "Thunnus maccoyii", "Epinephelus striatus",
"Sphyrna lewini", "Mobula mobular", "Isurus oxyrinchus", "Mustelus schmitti",
"Pseudotolithus senegalensis", "Sebastolobus alascanus", "Leucoraja circularis",
"Argyrosomus hololepidotus", "Raja undulata", "Isurus paucus",
"Thunnus thynnus", "Hippoglossus hippoglossus", "Merluccius senegalensis",
"Apostichopus japonicus", "Carcharhinus falciformis", "Carcharhinus longimanus",
"Lamna nasus", "Sphyrna zygaena", "Alopias vulpinus", "Cetorhinus maximus",
"Alopias superciliosus", "Carcharodon carcharias", "Sardinella maderensis",
"Galeorhinus galeus", "Pomatomus saltatrix", "Pentanemus quinquarius",
"Pseudupeneus prayensis", "Nemipterus virgatus", "Pseudotolithus senegallus",
"Dalatias licha", "Lutjanus campechanus", "Megalops atlanticus",
"Mola mola", "Mustelus mustelus", "Centrophorus squamosus", "Balistes capriscus",
"Centrophorus lusitanicus", "Leucoraja fullonica", "Rhomboplites aurorubens",
"Dentex dentex", "Epinephelus marginatus", "Palinurus elephas",
"Alosa immaculata", "Carcharhinus plumbeus", "Oxynotus centrina",
"Gymnura altavela", "Carcharias taurus", "Gadus morhua", "Melanogrammus aeglefinus",
"Thunnus obesus", "Trachurus trachurus", "Squalus acanthias",
"Makaira nigricans", "Thunnus orientalis"
),
Name_abbrev = c(
"S. argentina", "D. batis", "S. squatina", "T. maccoyii", "E. striatus", "S. lewini",
"M. mobular", "I. oxyrinchus", "M. schmitti", "P. senegalensis",
"S. alascanus", "L. circularis", "A. hololepidotus", "R. undulata",
"I. paucus", "T. thynnus", "H. hippoglossus", "M. senegalensis",
"A. japonicus", "C. falciformis", "C. longimanus", "L. nasus",
"S. zygaena", "A. vulpinus", "C. maximus", "A. superciliosus",
"C.carcharias", "S. maderensis", "G. galeus", "P. saltatrix",
"P. quinquarius", "P. prayensis", "N. virgatus", "P. senegallus",
"D. licha", "L. campechanus", "M. atlanticus", "M. mola", "M. mustelus",
"C. squamosus", "B. capriscus", "C. lusitanicus", "L. fullonica",
"R. aurorubens", "D. dentex", "E. marginatus", "P. elephas",
"A. immaculata", "C. plumbeus", "O. centrina", "G. altavela",
"C. taurus", "G. morhua", "M. aeglefinus", "T. obesus", "T. trachurus",
"S. acanthias", "M. nigricans", "T. orientalis"),
redlistCategory = structure(
c(
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L
),
.Label = c("CR", "EN", "VU"),
class = "factor"
),
TaxonGroup = structure(
c(
2L, 2L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 3L, 3L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 2L,
3L, 3L, 3L, 2L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 1L, 3L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 2L, 3L, 3L
),
.Label = c("Invertebrates", "Cartilaginous fish", "Bony fish"),
class = "factor"
),
totRank = c(
12, 39, 55, 7, 38, 56, 57, 8, 11, 17, 33, 36, 37, 50, 58, 6, 9, 16,
51, 15, 27, 30, 43, 45, 49, 52, 53, 5, 13, 14, 19, 20, 22, 23,
24, 25, 26, 28, 29, 31, 32, 34, 35, 40, 41, 42, 44, 46, 47, 48,
54, 59, 1, 2, 3, 4, 10, 18, 21),
VARIABLE = structure(
c(
3L, 3L, 3L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("CITES", "YES", "NO"),
class = "factor"
),
catch_ema_thousands = c(
3.886654422, 0.1724791016, 0.00911430205, 10.54412869, 0.174470439, 0.00807692997,
0.001640665002, 9.424452066, 6.583041893, 2.659608617, 0.2663195953,
0.2329239555, 0.2219422872, 0.01671489332, 0.0014159872, 13.44830652,
7.585155675, 2.774650025, 0.01599999, 3.024126379, 0.4539170316,
0.3113769576, 0.1163730191, 0.1011488649, 0.01681304105, 0.01561369792,
0.01416268544, 108.778465, 3.822553738, 3.251341729, 2.440669803,
1.688880545, 1.358903072, 1.100693581, 1.06694699, 0.8025907339,
0.5465603847, 0.4392502858, 0.3591757093, 0.2919081194, 0.2671983104,
0.2478545144, 0.2435067011, 0.15794176, 0.1539382418, 0.1226202735,
0.1079683714, 0.06792588753, 0.03801280875, 0.02357907878, 0.009323075655,
0.000514006594, 1652.737638, 484.1897672, 397.4311939, 153.0306153,
7.422144444, 2.459107988, 1.545317165)),
row.names = c(NA, -59L),
class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame")
)
)
#> structure(list(SpeciesOrTaxon = c("Squatina argentina", "Dipturus batis",
#> "Squatina squatina", "Thunnus maccoyii", "Epinephelus striatus",
#> "Sphyrna lewini", "Mobula mobular", "Isurus oxyrinchus", "Mustelus schmitti",
#> "Pseudotolithus senegalensis", "Sebastolobus alascanus", "Leucoraja circularis",
#> "Argyrosomus hololepidotus", "Raja undulata", "Isurus paucus",
#> "Thunnus thynnus", "Hippoglossus hippoglossus", "Merluccius senegalensis",
#> "Apostichopus japonicus", "Carcharhinus falciformis", "Carcharhinus longimanus",
#> "Lamna nasus", "Sphyrna zygaena", "Alopias vulpinus", "Cetorhinus maximus",
#> "Alopias superciliosus", "Carcharodon carcharias", "Sardinella maderensis",
#> "Galeorhinus galeus", "Pomatomus saltatrix", "Pentanemus quinquarius",
#> "Pseudupeneus prayensis", "Nemipterus virgatus", "Pseudotolithus senegallus",
#> "Dalatias licha", "Lutjanus campechanus", "Megalops atlanticus",
#> "Mola mola", "Mustelus mustelus", "Centrophorus squamosus", "Balistes capriscus",
#> "Centrophorus lusitanicus", "Leucoraja fullonica", "Rhomboplites aurorubens",
#> "Dentex dentex", "Epinephelus marginatus", "Palinurus elephas",
#> "Alosa immaculata", "Carcharhinus plumbeus", "Oxynotus centrina",
#> "Gymnura altavela", "Carcharias taurus", "Gadus morhua", "Melanogrammus aeglefinus",
#> "Thunnus obesus", "Trachurus trachurus", "Squalus acanthias",
#> "Makaira nigricans", "Thunnus orientalis"), Name_abbrev = c("S. argentina",
#> "D. batis", "S. squatina", "T. maccoyii", "E. striatus", "S. lewini",
#> "M. mobular", "I. oxyrinchus", "M. schmitti", "P. senegalensis",
#> "S. alascanus", "L. circularis", "A. hololepidotus", "R. undulata",
#> "I. paucus", "T. thynnus", "H. hippoglossus", "M. senegalensis",
#> "A. japonicus", "C. falciformis", "C. longimanus", "L. nasus",
#> "S. zygaena", "A. vulpinus", "C. maximus", "A. superciliosus",
#> "C.carcharias", "S. maderensis", "G. galeus", "P. saltatrix",
#> "P. quinquarius", "P. prayensis", "N. virgatus", "P. senegallus",
#> "D. licha", "L. campechanus", "M. atlanticus", "M. mola", "M. mustelus",
#> "C. squamosus", "B. capriscus", "C. lusitanicus", "L. fullonica",
#> "R. aurorubens", "D. dentex", "E. marginatus", "P. elephas",
#> "A. immaculata", "C. plumbeus", "O. centrina", "G. altavela",
#> "C. taurus", "G. morhua", "M. aeglefinus", "T. obesus", "T. trachurus",
#> "S. acanthias", "M. nigricans", "T. orientalis"), redlistCategory = structure(c(1L,
#> 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
#> 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
#> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
#> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("CR", "EN",
#> "VU"), class = "factor"), TaxonGroup = structure(c(2L, 2L, 2L,
#> 3L, 3L, 2L, 2L, 2L, 2L, 3L, 3L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 1L,
#> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 2L,
#> 3L, 3L, 3L, 2L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 1L, 3L, 2L, 2L, 2L,
#> 2L, 3L, 3L, 3L, 3L, 2L, 3L, 3L), .Label = c("Invertebrates",
#> "Cartilaginous fish", "Bony fish"), class = "factor"), totRank = c(12,
#> 39, 55, 7, 38, 56, 57, 8, 11, 17, 33, 36, 37, 50, 58, 6, 9, 16,
#> 51, 15, 27, 30, 43, 45, 49, 52, 53, 5, 13, 14, 19, 20, 22, 23,
#> 24, 25, 26, 28, 29, 31, 32, 34, 35, 40, 41, 42, 44, 46, 47, 48,
#> 54, 59, 1, 2, 3, 4, 10, 18, 21), VARIABLE = structure(c(3L, 3L,
#> 3L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L,
#> 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
#> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
#> 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("CITES", "YES",
#> "NO"), class = "factor"), catch_ema_thousands = c(3.886654422,
#> 0.1724791016, 0.00911430205, 10.54412869, 0.174470439, 0.00807692997,
#> 0.001640665002, 9.424452066, 6.583041893, 2.659608617, 0.2663195953,
#> 0.2329239555, 0.2219422872, 0.01671489332, 0.0014159872, 13.44830652,
#> 7.585155675, 2.774650025, 0.01599999, 3.024126379, 0.4539170316,
#> 0.3113769576, 0.1163730191, 0.1011488649, 0.01681304105, 0.01561369792,
#> 0.01416268544, 108.778465, 3.822553738, 3.251341729, 2.440669803,
#> 1.688880545, 1.358903072, 1.100693581, 1.06694699, 0.8025907339,
#> 0.5465603847, 0.4392502858, 0.3591757093, 0.2919081194, 0.2671983104,
#> 0.2478545144, 0.2435067011, 0.15794176, 0.1539382418, 0.1226202735,
#> 0.1079683714, 0.06792588753, 0.03801280875, 0.02357907878, 0.009323075655,
#> 0.000514006594, 1652.737638, 484.1897672, 397.4311939, 153.0306153,
#> 7.422144444, 2.459107988, 1.545317165)), row.names = c(NA, -59L
#> ), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"))
special.points <- special.points <- rownames(subset(
plotdat,
SpeciesOrTaxon %in% c(
"Gadus morhua", "Melanogrammus aeglefinus", "Thunnus obesus", "Trachurus trachurus",
"Sardinella maderensis", "Thunnus thynnus", "Thunnus maccoyii", "Hippoglossus hippoglossus",
"Squalus acanthias", "Merluccius senegalensis", "Epinephelus striatus", "Apostichopus japonicus",
"Mobula mobular", "Isurus oxyrinchus", "Mustelus schmitti", "Pseudotolithus senegalensis",
"Sebastolobus alascanus", "Leucoraja circularis", "Argyrosomus hololepidotus",
"Raja undulata", "Isurus paucus", "Sphyrna lewini", "Squatina argentina", "Dipturus batis",
"Squatina squatina", "Carcharhinus falciformis", "Squalus acanthias", "Makaira nigricans",
"Thunnus orientalis", "Carcharhinus longimanus", "Lamna nasus", "Sphyrna zygaena",
"Alopias vulpinus", "Cetorhinus maximus", "Alopias superciliosus", "Carcharodon carcharias",
"Palinurus elephas"
)
))
p <-
ggplot(data = plotdat,
aes(
x = -totRank,
y = catch_ema_thousands,
label = Name_abbrev
)) +
geom_point(
data = plotdat,
aes(color = VARIABLE),
size = 1.2,
shape = 1,
stroke = 0.8
) +
scale_color_manual(
values = c("black", "orange", "darkgrey"),
labels = c("CITES", "Intl trade", "No intl trade")
) +
facet_grid(redlistCategory ~ TaxonGroup,
scales = "free",
space = "free") +
geom_text_repel(
data = plotdat,
aes(
x = -totRank,
y = catch_ema_thousands,
label = Name_abbrev
),
# used the abbreviated species name to try and fit them better
segment.color = "black",
segment.size = 0.2,
segment.alpha = 0.5,
direction = "both",
min.segment.length = 0.5,
force = 10,
size = 2,
color = "black",
ylim = ylimits
) +
ylab("Average catch (thousand tonnes)") +
theme(
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
legend.position = "top",
legend.title = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black")
)
scales_y <- list(
CR = scale_y_sqrt(limits = c(0, 50), breaks = c(0, 50, 10)),
EN = scale_y_continuous(limits = c(0, 50), breaks = c(0, 50, 10)),
VU = scale_y_continuous(labels = scientific_format())
)
scales_x <- list(
'Invertebrates' = scale_x_discrete(limits = c(-50, -40)),
# plotting in reverse rank (-59 to 0)
'Cartilaginous fish' = scale_x_discrete(limits = c(-59, 0)),
'Bony fish' = scale_x_discrete(limits = c(-59, 0))
)
p + facet_grid_sc(redlistCategory ~ TaxonGroup, scales = list(x = scales_x, y = scales_y))
Created on 2019-09-04 by the reprex package (v0.3.0)
from facetscales.
I really appreciate your looking at this. However, the code above doesn't work in my environment. I get:
Error in `.rowNamesDF<-`(x, value = value) :
duplicate 'row.names' are not allowed
In addition: Warning messages:
1: In x[i] <- value[[j]] :
number of items to replace is not a multiple of replacement length
2: In x[i] <- value[[j]] :
number of items to replace is not a multiple of replacement length
3: In x[i] <- value[[j]] :
number of items to replace is not a multiple of replacement length
4: In x[i] <- value[[j]] :
number of items to replace is not a multiple of replacement length
5: In x[i] <- value[[j]] :
number of items to replace is not a multiple of replacement length
6: In x[i] <- value[[j]] :
number of items to replace is not a multiple of replacement length
7: non-unique values when setting 'row.names': ‘1’, ‘10’, ‘19’, ‘2’, ‘3’, ‘4’, ‘47’
Since this works for you, there may be an issue with my installed environment. Let me try and get a more straightforward example. In the mean time, should I use zeehio/facetscales@fix-panel-without-data rather than the base facetscales code?
from facetscales.
The fix-panel-without-data
branch will be merged in a few days (track the review and merge process here: #10), as I want to make sure it does not cause any unintended side effect.
Meanwhile feel free to install the branch:
devtools::install_github("zeehio/facetscales@fix-panel-without-data")
facetscales
is still an experimental package, changes might happen and things may break. It's up to you to use it in production.
from facetscales.
Related Issues (20)
- Unable to set variable scales of Y axis HOT 3
- Does it support scale_y_log10? HOT 4
- facet_wrap_sc HOT 1
- Problem in ggplot2 3.2.1 HOT 2
- Error in x$clone() : attempt to apply non-function HOT 2
- Error when using date column for x-axis HOT 3
- Error in x$clone() : attempt to apply non-function HOT 5
- attempt to select less than one element in get1index HOT 5
- facet_grid_sc does not seem to work with dates on x axis. HOT 2
- Did not make change with coord_flip() HOT 1
- help with geom_smooth and facet_grid_sc HOT 2
- What is the magnitude argument?
- Support multiple vars() HOT 2
- facet_grid_sc() throws error with POSIXct on x-axis. HOT 3
- Incompatible with expression()
- Error when faceting by column HOT 2
- Facet A, Facet B and others. HOT 2
- Boxplot looks different from facet_grid HOT 3
- facet_grid_sc cols argument not working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facetscales.