Rescaling the y axis in bar plot causes bars to disappear : R ggplot2
Try this
p + coord_cartesian(ylim=c(200,300))
Setting the limits on the coordinate system performs a visual zoom;
the data is unchanged, and we just view a small portion of the original plot.
geom_bar bars not displaying when specifying ylim
You could try, with library(scales)
:
+ scale_y_continuous(limits=c(2000,2500),oob = rescale_none)
instead, as outlined here.
How to adjust the Bar plot to make the bars smaller?
If it's just a matter of width, you can specify it in this way:
bxp <- ggboxplot(df, x = "supp", y = "len", fill = "supp",
palette = c("#00AFBB", "#E7B800"),width = 0.5)
stat.test <- stat.test %>% add_xy_position(x = "supp")
bxp + stat_pvalue_manual(
stat.test, label = "T-test, p = {p}",
vjust = -1, bracket.nudge.y = 1
) +
scale_y_continuous(expand = expansion(mult = c(0.05, 0.15)))+
scale_x_discrete(expand = c(2, 2))
then, using the rest it looks like this:
Is that what you wanted?
Get missing value errors while draw a bar-line mixed and dual y axis plot in ggplot2
It works after adding scale_x_yearqtr(oob = scales::oob_keep, ...)
, thanks to @teunbrand.
ggplot() +
geom_bar(data = df_m_x, aes(x = date, y = value, fill = variable), alpha = 1.0, stat = 'identity') +
geom_line(data = df_m_ratio_x, aes(x = date, y = value, col = variable), size = 0.5) +
geom_point(data = df_m_ratio_x, aes(x = date, y = value, col = variable), size = 1) +
xlab('') +
scale_y_continuous(
name = "dollar",
sec.axis = sec_axis(~.*coeff, name = "%")) +
scale_color_manual(values = c("a" = "#00AFBB")) +
scale_x_yearqtr(oob = scales::oob_keep, limits = c(min(df$date), max(df$date)), format = "%YQ%q")
R barplot axis scaling
Not sure exactly what you wnat, but If it is to have the labels running from one end to the other evenly places (but not necessarily accurately), then:
x = c(1:81)
bp <- barplot(x)
axis(side=1,at=bp[1+c(0,20,40,60,80)],labels=c(20,40,60,80,100))
The puzzle for me was why you wanted to label "20" at 0. But this is one way to do it.
Error Bars on Bar Plot are Incorrectly Shaped
The below does what you want. I used pivot_longer
(newer version of gather
) to gather the correct SD and Mean together. In the plot, I added color = Sample
to the ggplot()
call, which makes sure the position="dodge"
dodges the different errorbars.
pd <- peak_intersect_rep_elements_means %>%
mutate(Antibody = factor(Antibody, sample_order)) %>%
select(Sample, Mean_Alu_frac,
Mean_L1_frac, Antibody, CellLine, SD_Alu_frac, SD_L1_frac)
pd <- pd %>%
pivot_longer(ends_with("_frac"),
names_pattern = "(.*)_(.*)_frac",
names_to = c(".value", "metric"))
pd %>%
ggplot(aes(Antibody, Mean, fill = metric, color = Sample)) +
facet_wrap(~CellLine, scales = 'free_x') +
geom_bar(stat = "identity", position = "dodge", size = 0.1) +
geom_errorbar(aes(ymin=Mean - SD , ymax=Mean + SD), width=.3,
position=position_dodge(.9)) +
scale_color_manual(values = c("ADAR062" = "black", "ADAR112" = "black",
"ADAR004" = "black")) +
scale_fill_manual(values = c("Alu" = "#125863",
"L1" = "#2BA8B3")) +
scale_y_continuous(labels = scales::percent) +
guides(color = F) +
theme_minimal() +
labs(y = '', x = '', color = '', fill = 'Rep element',
title = "Intersection of ADAR1 IP peaks and repetetive elements")
Related Topics
Installing R 3.5.0 with --Enable-R-Shlib
Link Selectinput with Sliderinput in Shiny
R Reading in a Zip Data File Without Unzipping It
Remove Rows Where All Variables Are Na Using Dplyr
Ggplot2 Theme with No Axes or Grid
Force Ggplot2 Scatter Plot to Be Square Shaped
Ggplot: Multiple Years on Same Plot by Month
Multiple Functions in a Single Tapply or Aggregate Statement
Meaning of Objects Being Masked by the Global Environment
How to Get Pixel Data from an Image Using R
How to Get a Warning on "Shiny App Will Not Work If the Same Output Is Used Twice"
Selection of Activity Trace in a Chart and Display in a Data Table in R Shiny
How to Do a Data.Table Merge Operation
Generating a Vector of Difference Between Two Vectors
How to Preserve Base Data Frame Rownames Upon Filtering in Dplyr Chain
Cor Shows Only Na or 1 for Correlations - Why
Figure Out What Version of R a Function Was Introduced In
Summarise_At Using Different Functions for Different Variables