1

I have csv files that each has multiple stack plot, but input csv files named with rather long character. However, in my resulted plot, full name of csv files not fully printed in facet_wrap which easily confused category of plot are referring to. I am trying to adjust the size of face_wrap by using space, scale parameter, but full name of input csv files still is not displayed. Can anyone point me how to deal with csv files with rather long pattern that must be displayed in resulted plot ? How can I make this happen ? Any idea ?

I have csv file which named with rather long character (just toy example here) :

TextTextTextTextTextTextTextTextTextTextTextTextTextText.csv

This is my resulted plot and desired plot that I want to achieve (here I showed multiple stack plot for only one csv file) :

enter image description here

I intend to continue the code part of my original plot. How can I get my desired plot ? Any way to tune size of face_wrap where rather long named file can be displayed in resulted plot ? Thanks a lot :)

Edit :

I want to adjust the space between multiple stack plot for each csv file as well. If multiple plot of two or three csv files are placed in one single page, How to dynamically adjust space, and plot size that make sure rather long named csv files are more readable. How can I achieve this ? Any idea please ?

New Edit :

Qualified <- list(
    hotankarmaykuchakorla = data.frame( begin=seq(1, by=6, len=20), end=seq(4, by=6, len=20), pos.score=sample(30, 20)),
    aksukexkerawataltay = data.frame( begin=seq(3, by=9, len=15), end=seq(6, by=9, len=15), pos.score=sample(28, 15))
)

UnQualified <- list(
    hotankarmaykuchakorla = data.frame( begin=seq(9, by=12, len=30), end=seq(14, by=12, len=30), pos.score=sample(35, 30)),
    aksukexkerawataltay = data.frame( begin=seq(13, by=10, len=20), end=seq(19, by=10, len=20), pos.score=sample(34, 20))
)

get multiple stack plot for this:

hotankarmaykuchakorla.validCandidate.Qualified.csv
hotankarmaykuchakorla.validCandidate.unQualified.csv
hotankarmaykuchakorla.invalidCandidate.Qualified.csv
hotankarmaykuchakorla.invalidCandidate.UnQualified.csv
Jerry07
  • 929
  • 1
  • 10
  • 28

1 Answers1

2

Maybe using newline:

library(ggplot2)

# dummy data
df1 <- mtcars[, 1:3]
# make new long name
df1$cyl <- paste0("TextTextTextTextTextTextTextTextTextText", df1$cyl, ".csv")
# add newline
df1$cylWrap <- 
  paste0(substr(df1$cyl, 1, 20), "\n",
         substr(df1$cyl, 21, nchar(df1$cyl)))

# plot
ggplot(df1, aes(mpg, disp)) +
  geom_col() +
  facet_wrap( ~cylWrap, scales = "free_x") +
  theme(text = element_text(size = 14))

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209