[R] Issue with crammed Y axis

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sun Jun 18 09:11:13 CEST 2023


Às 00:07 de 17/06/2023, Ana Marija escreveu:
> Hi,
> 
> I have a data frame like this:
> 
>> dput(df)
> structure(list(ID = 1:8, Type = c("gmx mdrun -ntmpi 8 -ntomp 1 -s
> benchPEP.tpr -nsteps 10000 -resethway",
> "gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps 10000 -resethway",
> "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps 4000 -resetstep 3000",
> "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps 4000 -resetstep 3000",
> "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps -1 -maxh 1.0 -resethway",
> "gmx mdrun -ntmpi 8 -s benchPEP.tpr -nsteps -1 -maxh 1.0 -resethway",
> "gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps -1 -maxh 1.0
> -resethway -noconfout",
> "gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps -1 -maxh 1.0
> -resethway -noconfout"
> ), Annee = c("SYCL", "CUDA", "SYCL", "CUDA", "SYCL", "CUDA",
> "SYCL", "CUDA"), Domain.decomp. = c("2. 1", "2", "2. 1", "2. 1",
> "2.1", "2", "2. 1", "2"), DD.com..load = c(0, 0, 0, 0, 3.7, 3,
> 0, 0), Neighbor.search = c("3.7", "3. 1", "3.7", "3.9", "0. 1",
> "O. 1", "3.5", "3. 1"), Launch.PP.GPU.ops. = c("0. 1", "0", "0.2",
> "0", "1 .6", "1 . 5", "0.2", "0. 1"), Comm..coord. = c("1 .6",
> "1 .0", "1 .5", "1 .3", "1 .5", "1 .3", "1 . 5", "1 .6"), Force = c("1 .
> 5",
> "1 .2", "1 .4", "1 .2", "1 .3", "1 . 1", "1 .5", "1 .2"), Wait...Comm..F =
> c("1 .3",
> "1 .7", "1 .2", "1 .0", "66.7", "68.8", "1 .2", "1 .2"), PIE.mesh =
> c("65.6",
> "70.9", "61 .0", "61 .4", "0", "0", "67.6", "69.2"), Wait.Bonded.GPU =
> c(0L,
> 0L, 0L, 0L, 0L, 0L, 0L, 0L), wait.GPU.NB.nonloc. = c(0L, 0L,
> 0L, 0L, 0L, 0L, 0L, 0L), Wait.GPU.NB.local = c(0, 0, 0, 0, 7.4,
> 5.7, 0, 0), NB.X.F.buffer.ops. = c("7.3", "4.4", "6. 7", "5",
> "0. 1", "0. 1", "7.2", "5.5"), Write.traje = c("0.3", "0.3",
> "1 .2", "1 .3", "6.4", "6. 1", "O. 1", "0. 1"), Update = c(6.3,
> 4.3, 5.7, 4.9, 8.2, 9.5, 6.2, 5.6), Constraints = c("8.9", "9.7",
> "1 1 .6", "13.3", "0.3", "0.4", "8. 1", "9.5"), Comm..energies = c("0.9",
> "0.9", "3.3", "3.9", "8.4", "8. 5", "0.3", "0.4"), PIE.redist..X.F = c("8.
> 1",
> "8.7", "7.9", "7.4", "29.9", "30.1", "8. 1", "8. 1"), PIE.spread =
> c("29.7",
> "30.6", "27.2", "29.6", "20.3", "20.2", "30. 1", "30.4"), PIE.gather =
> c("19.9",
> "21 .3", "18.7", "19", "6.4", "8.4", "20", "20.6"), PIE.3D.FFT = c("6",
> "8.6", "5.7", "4.3", "1 .0", "1 .1", "7.6", "8.4"), PIE.3D.FFT.comm. = c("1
> .2",
> "1 .0", "0.9", "0.7", "1 .2", "0. 5", "1 .0", "1 .1"), PIE.solve.Elec =
> c(0.7,
> 0.5, 0.6, 0.3, 0.7, 0.5, 0.7, 0.5)), class = "data.frame", row.names =
> c(NA,
> -8L))
> 
> I am plotting this data with:
> 
> library(reshape2)
> library(ggplot2)
> 
> df <- read.csv("/Users/anamaria/Downloads/B5.csv", stringsAsFactors=FALSE,
> header=TRUE)
> 
> df.long<-melt(df,id.vars=c("ID","Type","Annee"))
> 
> myplot =ggplot(df.long,aes(variable,value,fill=as.factor(Annee)))+
>     geom_bar(position="dodge",stat="identity")+
>     ylab("Simulation Progress (%)") +
>     facet_wrap(~Type,nrow=3)
> 
> myplot + theme(panel.grid.major = element_blank(),
> legend.title=element_blank(), panel.grid.minor = element_blank(),
> panel.background = element_blank(), axis.title.x = element_blank(),
> axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
> axis.line = element_line(colour = "black"))
> 
> My issue is that Y axis is crammed. How it can be cleaned up and say
> feature only say these values: 0, 10, 20,30, ...80.
> 
> I tried using: scale_y_continuous(breaks = breaks_width(10))+
> But I got this error:
> Error in breaks_width(10) : could not find function "breaks_width"
> 
> Also can anything be done about the subtitle of the top left plot, which is
> not quite fitting in that gray box: "
> gmx mdrun -ntmpi 8 -ntomp 1 -s benchPEP.tpr -nsteps 10000 -resethway"
> 
> Thanks
> Ana
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Hello,

The problem seems to be that df.long$value is character and that it has 
spaces and "O" (upper case letter O) in it. Try, before plotting


df.long$value <- gsub(" ", "", df.long$value)
df.long$value <- sub("O", "0", df.long$value)
df.long$value <- as.numeric(df.long$value)


With me it solved the problem.

As for breaks_width, that's a function in package scales, so if the 
above doesn't solve it, qualify the function name:


scale_y_continuous(breaks = scales::breaks_width(10)) +


Hope this helps,

Rui Barradas



More information about the R-help mailing list