0
votes

I have a dataset of a type as shown

Seasons        A        B        C        A1        B1        C1  
Winter         97       94       87       0.2       0.4       0.3  
Summer         92       94       101      1         0.7       0.3
 

There are values for each season (Summer, Winter, autumn, spring) and with variables from (A to E) and (A1 to E1). While drawing a barplot using ggplot2, the bar height of A1 to E1 is very less due to their low values and I wish to move them to the secondary axis but I don't know how to do that. Please suggest the code. I am sharing my code until now.

library(readxl)
library(ggplot2)
library(readxl)
cell_viability_data <- read_excel("C:/Users/CEZ178522/Downloads/ananya/Cell_viability.xlsx")
cell_viability_data


plot1 <- ggplot(data=cell_viability_data, aes(x=Seasons, y= CellViability, fill= Types)) +
  geom_bar(stat="identity", position=position_dodge()) +
             labs(title = "Seasonal Cell Viability") +
             theme(axis.text.x = element_text(colour = "grey1", size = 10),
                   axis.text.y = element_text(colour = "grey1", size = 10),
                   plot.title = element_text(hjust = 0.5))
plot1

enter image description here

I need the small bars to move to secondary axis

1

1 Answers

0
votes

Secondary y-axes were for a long time banned in ggplot because they usually do more damage than good. The only option for now is to display an auxiliary, secondary y-axis which has a direct, proportional transformation from the primary y-axis. In other words, the secondary y-axis is a supplemental axis which displays the same information, but on a different scale (thing Celcius and Fahrenheit).

What you are asking is to have a subset of data points inflated by some arbitrary value, so they are "on par" with the remaining. Consider this: Can you, by choice of scaling constant, make values A1-E1 appear much higher than values A-E? Can you, by choice of scaling constant, make values A1-E1 appear much, much lower than values A-E? Can you, by choice of scaling constant, make values A1-E1 be "on par" with A-E, but always slighter lower? If so, to any question, your data visualisation cannot be trusted.

Consider instead: What is the important comparison you are trying to make? Season-to-season for each type? A vs. A1? Take out a pen and paper, and try to sketch what you want to compare, and what issues you are encountering when making a comparison. Then you are ready to make the visualisation in R/ggplot.