logarithmic y-axis issue in R/ ggplot2

Viewed 44

I plotted a histogram from a frequency distribution table using ggplot2. Here is some sample data

dput(test_data)
structure(list(inst = c(5, 5, 5, 10, 10, 10, 15, 15, 15), equip = c("a", 
"b", "c", "a", "b", "c", "a", "b", "c"), value = c(0.520670542493463, 
0.7556017707102, 0.931902746669948, 0.206132101127878, 0.0114199279341847, 
0.603053622646257, 0.315444506937638, 0.375196750741452, 0.983124621212482
)), class = "data.frame", row.names = c(NA, -9L))

When I use ggplot2 to plot the data, I get the following output:

test_hist1 <- ggplot(test_data,aes(x = inst, y =value, fill = equip)) + geom_bar(width=3,alpha=1,stat = "dodge", position ="stack")+theme_bw()+xlab(expression(Value))+ylab("value") + ggtitle(expression(test~data))+theme(plot.title = element_text(hjust = 0.5))+scale_fill_manual(values=c("#00FF00", "#FFD700","#DC143C"))

enter image description here

But when I transform the y_axis to be a log_axis, the plot direction changes and so does the intensity of the bars.

test_hist2 <- ggplot(test_data,aes(x = inst, y =value, fill = equip)) + geom_bar(width=3,alpha=1,stat = "dodge", position ="stack")+theme_bw()+xlab(expression(Value))+ylab("log_yaxis") + ggtitle(expression(test~data))+theme(plot.title = element_text(hjust = 0.5))+scale_fill_manual(values=c("#00FF00", "#FFD700","#DC143C"))+scale_y_log10()

enter image description here

My second plot is wrong, because the code for second plot is just converting my y-axis number to log10(y_axis_value) instead of a log_axis that is given in the following answer (the plot in the answer is the axis I am looking for). Can someone direct me in the right direction. Thanks for the help.

R: Difference between log axis scale vs. manual log transformation?

0 Answers
Related