2

I have been using R for 6 months now (fairly new). I have created a nice graph using the facet_wrap funciton, with geom_point.

However, i don't seem to have success with geom_col, when plotting another parameter i am interested in.

The code is below:

T <- Titers %>% 
ggplot(aes(Sample_ID, Titer)) + 
geom_col(aes(col=Day), size=1.1) + 
facet_wrap(Strategy~Additives) + 
scale_color_manual(values = Ahmad) + 
ylab('Titer mg/L') + 
xlab('Time (Day)') + 
ggtitle('All data') + 
geom_label_repel(aes(label = Sample_ID), data = tail(Titers, 14), nudge_x = 
2, direction = "y", segment.size = 0.2, hjust = 0) + theme(strip.text.x = 
element_text(size = 12), axis.title = element_text(size = 14), axis.text = 
element_text(size = 14), legend.position = "none")

The code that have been working fine is the following:

Q2 <- USP20005 %>% 
ggplot(aes(Day, Diameter)) + 
geom_line(aes(col=Sample_ID), size=1.1) + 
facet_wrap(Strategy~Additives) + 
scale_color_manual(values = Ahmad) + 
ylab('VCD E6 cells/mL') + 
xlab('Time (Day)') + 
ggtitle('All data') + 
geom_label_repel(aes(label = Sample_ID), data = tail(USP20005, 24), nudge_x 
= 2, direction = "y", segment.size = 0.2, hjust = 0) + 
theme(strip.text.x = element_text(size = 12), axis.title = element_text(size =
14), axis.text = element_text(size = 14), legend.position = "none") + 
scale_x_continuous(breaks = seq(0, 14, 2), limits = c(0, 14)) + 
scale_y_continuous(breaks = seq(10, 20, 2), limits = c(10, 20))

Failed graph

successful graph

Why are there spaces vetween the columns, even though i used facet_warp to split the samples into different boxes (it seems R is still reserving the empty spots?)

Just to be clear: I want to see every 2-4 samples together in on box, where the bars for each sample on the different days are stuck to each other. I WAS able to plot them stacked, but i dont want that.

What am I doing wrong here? Any help would be much appreciated.

Thank you in advance Ahmad

Ahmad
  • 23
  • 4

1 Answers1

0

If you use scale_x_*(), the x-axis will be fixed and maintain the spaces.

Alan Dursun
  • 655
  • 3
  • 14