Scatterplot: split x values on two axis (bottom/top) with one y axis

Hello and happy Easter everybody!

Regarding the dataset and scatterplot below, I would like to know if it would be generally possible to split the x axis (60 values) in half and subsequently create a second x axis on top of the graph with a corresponding staggered visualization of the dots on the same y axis for the reason of space gain of the whole graph itself.

Thank you already sincerely for any advice and support!

data.frame(
stringsAsFactors = FALSE,
check.names = FALSE,
Company = c("NIED KUNSTSTOFF-TEXTIL",
"Nagel GmbH","BD SENSORS GmbH","TECHNOCHEM GMBH",
"Xaver Bosch","GEMA-Technik GmbH","Linker Industrie-Technik GmbH",
"Element Metech KDK GmbH","Heinzelmann GmbH",
"Intercontact GmbH","IAG GLUSKA GmbH ","AZS System AG",
"UM Electronic GmbH","Maprotec GmbH",
"CubiDesign Gehäuse GmbH","Q-BAT Oberflächen","Tucker GmbH","EMO Systems GmbH",
"EPN ELECTROPRINT GmbH","FOLA Abfülltechnik GmbH",
"YachtelektrONik Höppli","Vereinsbedarf Deitert GmbH",
"Haag Druck","Benz Alusysteme GmbH","B2B Hygiene e.Kfm",
"Peer-Span GmbH","ORDAT GmbH & Co. KG","Labomedic GmbH",
"Julius Blum GmbH","Nadella GmbH","RAMPF Technik",
"Ruhrbotics GmbH","m2m Germany GmbH","MABECO GmbH & Co. KG",
"System4all GmbH ","SAB Sägewerksanlagen GmbH",
"Fabian GmbH ","babp GmbH","Haas Sanitär","Ueberholz GmbH",
"WaBaCom GmbH","CSD Logistik Software GmbH",
"East-Tex GmbH","Eberspächer GmbH ","UGT 2000 GmbH",
"jafoplast GmbH","AAE Studio","SACCESS GmbH ",
"OBS Michalzik GmbH ","easyhyp GmbH ","MABEG Kreuschner","CEFIC",
"Gabory GmbH","Eberle Motoren GmbH","Saco Shipping GmbH",
"VRG CURAMUS GmbH","takuma OHG","Lace up! GmbH",
"Aagris e.K.",NA),
2017 = c(658187,254310,67826,473905,
735155,85546,876751,529764,355106,807324,671716,
866008,437234,676152,609098,968959,662482,367870,
525664,37733,477261,698401,485506,273852,376309,
826602,528832,803242,964322,608001,452039,669047,531454,
472688,712816,198140,587134,591129,546467,335460,
422745,314735,10531,723850,281095,682451,413384,
554999,261103,343448,512427,643661,760153,274679,
243492,190308,75825,735591,717542,427028),
2018 = c(727560,393289,104807,461526,
742667,81128,741267,598991,336967,816577,722132,
NA,772505,642375,540570,977253,753632,384648,526915,
51331,467907,725131,611686,261114,372124,830571,
511309,770075,881413,645145,502556,644972,442182,
373413,714513,208348,634342,626435,541061,443105,
615172,459462,16845,925239,220573,632661,461929,
523132,306272,202952,373733,682938,746800,385506,12777,
240561,96953,925368,741840,548611),
2019 = c(665346,247203,99166,495720,
786560,108115,943064,753831,373828,727487,891883,
NA,810404,595123,485798,923987,891428,521718,468212,
81447,606135,604271,944775,324888,429558,931834,
555963,770818,851152,762138,570597,616615,555044,
208589,862103,206624,636662,697567,626551,664949,
807946,454060,32776,869305,251651,619315,1337257,
645966,314475,522952,317399,693273,789966,453411,NA,
259981,207535,1013013,773367,563635),
2020 = c(741295,202858,92558,527192,
454681,130124,840286,1106443,373828,768923,562355,
NA,645502,595123,478402,978969,991798,513075,
604918,96406,NA,295270,863120,234664,508872,910187,
573186,786599,NA,NA,663679,NA,622908,NA,626653,
173207,724342,735178,682081,613924,1238149,NA,80635,
764198,315208,694729,1297585,401089,296099,289966,
203257,749571,798384,497972,NA,311898,200106,
1134086,702934,599833),
2021 = c(843014,202629,48866,553427,
856747,112258,NA,1125463,414871,865362,746239,NA,
702647,595123,NA,946340,784076,NA,799148,158311,
NA,478784,786928,NA,621963,927921,573133,852666,NA,
NA,754847,NA,568862,NA,652273,195991,730798,
755924,660670,887816,1791138,NA,NA,192792,388744,NA,
1366060,557443,276777,229632,168365,795699,817638,
631140,NA,320348,281204,1032339,708842,461453)
)

library(tidyr)
CL1 <- data1 %>% pivot_longer(!Company, names_to = "status", values_to = "Costs")

library(ggplot2)
ggplot(CL1, aes(Company, Costs, fill = status) ) +
geom_point(aes(shape = status)) +
labs(y = "Total number of Costs") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))

I think it can be done but what about just flipping the graph?

ggplot(CL1, aes(Company, Costs, colour = status) ) +
  geom_point(aes(shape = status)) +
  labs(y = "Total number of Costs") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  coord_flip()

BTW, I had trouble reading your data. The purely numeric "year" values seem to be a problem so I added a "Y" in front of each one. Oh, I also changed "fill = ' to "colour =". Apparently geom_point() does not have a "fill" option.

data1  <- structure(list(Company = c("NIED KUNSTSTOFF-TEXTIL", "Nagel GmbH", 
"BD SENSORS GmbH", "TECHNOCHEM GMBH", "Xaver Bosch", "GEMA-Technik GmbH", 
"Linker Industrie-Technik GmbH", "Element Metech KDK GmbH", "Heinzelmann GmbH", 
"Intercontact GmbH", "IAG GLUSKA GmbH ", "AZS System AG", "UM Electronic GmbH", 
"Maprotec GmbH", "CubiDesign Gehäuse GmbH", "Q-BAT Oberflächen", 
"Tucker GmbH", "EMO Systems GmbH", "EPN ELECTROPRINT GmbH", "FOLA Abfülltechnik GmbH", 
"YachtelektrONik Höppli", "Vereinsbedarf Deitert GmbH", "Haag Druck", 
"Benz Alusysteme GmbH", "B2B Hygiene e.Kfm", "Peer-Span GmbH", 
"ORDAT GmbH & Co. KG", "Labomedic GmbH", "Julius Blum GmbH", 
"Nadella GmbH", "RAMPF Technik", "Ruhrbotics GmbH", "m2m Germany GmbH", 
"MABECO GmbH & Co. KG", "System4all GmbH ", "SAB Sägewerksanlagen GmbH", 
"Fabian GmbH ", "babp GmbH", "Haas Sanitär", "Ueberholz GmbH", 
"WaBaCom GmbH", "CSD Logistik Software GmbH", "East-Tex GmbH", 
"Eberspächer GmbH ", "UGT 2000 GmbH", "jafoplast GmbH", "AAE Studio", 
"SACCESS GmbH ", "OBS Michalzik GmbH ", "easyhyp GmbH ", "MABEG Kreuschner", 
"CEFIC", "Gabory GmbH", "Eberle Motoren GmbH", "Saco Shipping GmbH", 
"VRG CURAMUS GmbH", "takuma OHG", "Lace up! GmbH", "Aagris e.K.", 
NA), Y2017 = c(658187, 254310, 67826, 473905, 735155, 85546, 
876751, 529764, 355106, 807324, 671716, 866008, 437234, 676152, 
609098, 968959, 662482, 367870, 525664, 37733, 477261, 698401, 
485506, 273852, 376309, 826602, 528832, 803242, 964322, 608001, 
452039, 669047, 531454, 472688, 712816, 198140, 587134, 591129, 
546467, 335460, 422745, 314735, 10531, 723850, 281095, 682451, 
413384, 554999, 261103, 343448, 512427, 643661, 760153, 274679, 
243492, 190308, 75825, 735591, 717542, 427028), Y2018 = c(727560, 
393289, 104807, 461526, 742667, 81128, 741267, 598991, 336967, 
816577, 722132, NA, 772505, 642375, 540570, 977253, 753632, 384648, 
526915, 51331, 467907, 725131, 611686, 261114, 372124, 830571, 
511309, 770075, 881413, 645145, 502556, 644972, 442182, 373413, 
714513, 208348, 634342, 626435, 541061, 443105, 615172, 459462, 
16845, 925239, 220573, 632661, 461929, 523132, 306272, 202952, 
373733, 682938, 746800, 385506, 12777, 240561, 96953, 925368, 
741840, 548611), Y2019 = c(665346, 247203, 99166, 495720, 786560, 
108115, 943064, 753831, 373828, 727487, 891883, NA, 810404, 595123, 
485798, 923987, 891428, 521718, 468212, 81447, 606135, 604271, 
944775, 324888, 429558, 931834, 555963, 770818, 851152, 762138, 
570597, 616615, 555044, 208589, 862103, 206624, 636662, 697567, 
626551, 664949, 807946, 454060, 32776, 869305, 251651, 619315, 
1337257, 645966, 314475, 522952, 317399, 693273, 789966, 453411, 
NA, 259981, 207535, 1013013, 773367, 563635), Y2020 = c(741295, 
202858, 92558, 527192, 454681, 130124, 840286, 1106443, 373828, 
768923, 562355, NA, 645502, 595123, 478402, 978969, 991798, 513075, 
604918, 96406, NA, 295270, 863120, 234664, 508872, 910187, 573186, 
786599, NA, NA, 663679, NA, 622908, NA, 626653, 173207, 724342, 
735178, 682081, 613924, 1238149, NA, 80635, 764198, 315208, 694729, 
1297585, 401089, 296099, 289966, 203257, 749571, 798384, 497972, 
NA, 311898, 200106, 1134086, 702934, 599833), Y2021 = c(843014, 
202629, 48866, 553427, 856747, 112258, NA, 1125463, 414871, 865362, 
746239, NA, 702647, 595123, NA, 946340, 784076, NA, 799148, 158311, 
NA, 478784, 786928, NA, 621963, 927921, 573133, 852666, NA, NA, 
754847, NA, 568862, NA, 652273, 195991, 730798, 755924, 660670, 
887816, 1791138, NA, NA, 192792, 388744, NA, 1366060, 557443, 
276777, 229632, 168365, 795699, 817638, 631140, NA, 320348, 281204, 
1032339, 708842, 461453)), class = "data.frame", row.names = c(NA, 
-60L))

Thank you very much @jrkrideau already for your immediate answer! I also thought about flipping, however overall, I have to deal with a bigger number of graphs with a maximum range of x up to 120. Due to the given limits of scientific journals, I wondered if it would be possible to increase a readability and save space by using the "untouched" top area of the graph.

Without a better idea of what the substantive question in, I don't think I can even make a guess.

Unless your space constraints are really nasty (Science or Nature?) what about just splitting the data on some reasonable criterion(ia) and doing two or more plots in a panel using {patchwork} or {cowplot}?

I still like the idea of having the company names on the y-axis. It greatly improves readability.

Also, it looks to me that you would get better comprehension splitting the plots by year but this might be starting to get to monograph size if not a book.

ggplot(CL1, aes(Costs, Company, colour = status ) ) +
  geom_point(aes(shape = status),  show.legend = FALSE) +
  labs(x = "Total number of Costs") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  facet_grid(~ status)


Sorry to be of so little help.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.