Rescaling the Y Axis in Bar Plot Causes Bars to Disappear:R Ggplot2

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.

barplot example

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:

Sample Image

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



Leave a reply



Submit