I have code like this:
data <- read.csv("test2.csv", stringsAsFactors=FALSE, header=TRUE)
# Graph
myplot=ggplot(data, aes(fill=condition, y=value, x=condition)) +
geom_bar(position="dodge", stat="identity") +
scale_fill_manual(values=c("#ffffb2", "#fecc5c"))+
scale_y_discrete(breaks=c(10,20,30,40,50,60,70,80))+
ylab("Performance (ns/day) on Extreme") +
facet_wrap(~specie,nrow=3, labeller = label_wrap_gen(width = 85)) +
theme_bw() +
theme(panel.grid = element_blank(),
panel.spacing = unit(0, "mm"),
legend.title=element_blank(),
axis.title.x = element_blank(),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
myplot + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), legend.title=element_blank(),
panel.background = element_blank(), axis.title.x = element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), axis.title.y = element_text(angle = 90, hjust = 0.5, size = 20))
My data is this:
> dput(data)
structure(list(specie = c("gmx mdrun -s benchMEM.tpr -nsteps 10000",
"gmx mdrun -s benchMEM.tpr -nsteps 10000", "gmx mdrun -s benchPEP.tpr -nsteps 10000 ",
"gmx mdrun -s benchPEP.tpr -nsteps 10000 ", "gmx mdrun -s benchPEP-h.tpr -nsteps 10000 ",
"gmx mdrun -s benchPEP-h.tpr -nsteps 10000 ", "gmx mdrun -s MD_5NM_WATER.tpr -nsteps 10000 ",
"gmx mdrun -s MD_5NM_WATER.tpr -nsteps 10000 ", "gmx mdrun -s data/MD_10NM_WATER.tpr -nsteps 10000 ",
"gmx mdrun -s data/MD_10NM_WATER.tpr -nsteps 10000 ", "gmx mdrun -s MD_15NM_WATER.tpr -nsteps 10000 ",
"gmx mdrun -s MD_15NM_WATER.tpr -nsteps 10000 "), condition = c("CUDA",
"SYCL", "CUDA", "SYCL", "CUDA", "SYCL", "CUDA", "SYCL", "CUDA",
"SYCL", "CUDA", "SYCL"), value = c("54.682", "77.649", "0.673",
"0.841", "0.86", "0.986", "452.48", "158 .277", "81.426", "80.454",
"33.449", "34.363")), class = "data.frame", row.names = c(NA,
-12L))
I did set ticks on y axis via:
scale_y_discrete(breaks=c(10,20,30,40,50,60,70,80))+
but they are not showing up. Please advise how to fix this. If I don't include scale_y_discrete decimal values are showing up on y axis which is not what I want.
In addition to using as.numeric()
as @Phil suggests in a comment, I removed whitespace from one of the values (158 .277). If you find additional NAs are introduced in the full data frame, the value
column may require some clean up before coercing to numeric.
With the y-axis data set as a numeric, you don't necessarily need to adjust the scales yourself. In your theme()
you set axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)
and then add axis.text.x=element_blank()
, so I have only kept the latter in these plots.
library(dplyr)
library(ggplot2)
myplot <- data %>%
mutate(value = as.numeric(value)) %>%
ggplot(aes(fill=condition, y=value, x=condition)) +
geom_bar(position="dodge", stat="identity") +
scale_fill_manual(values=c("#ffffb2", "#fecc5c"))+
ylab("Performance (ns/day) on Extreme") +
facet_wrap(~specie,nrow=3, labeller = label_wrap_gen(width = 85)) +
theme_bw() +
theme(panel.grid = element_blank(),
panel.spacing = unit(0, "mm"),
legend.title=element_blank(),
axis.title.x = element_blank(),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.ticks.x=element_blank(),
axis.title.y = element_text(angle = 90, hjust = 0.5, size = 20))
myplot
If you decide you do want to control the y-axis, you would use scale_y_continuous()
instead of discrete
.
myplot +
scale_y_continuous(breaks = c(0,50,250,400))
myplot +
scale_y_continuous(breaks = scales::breaks_extended(n = 12))
Created on 2023-06-26 with reprex v2.0.2