I have a peculiar problem involving the use of the trans and label commands in scale_y_continuous within ggplot2.
With toy data, things seem to work correctly, combining the scale_y_continus trans function with labels = scales::dollar. So this code
y <- c(0,2,4,6,3,2,6,1000)
x <- c(1,2,3,4,5,6,7,8)
z <- c("One", "One", "One", "One", "two", "two", "two", "two")
df <- data.frame(x,y, z)
df%>%
ggplot()+
geom_col(aes(x=x, y=y, fill=z))+
scale_y_continuous(trans="log10", labels=scales::dollar)
The result is this: which is right.
However, when I try this with my data (cannot be shared, unfortunately) the scale for the y axis goes ballistic (I ended with like trillions on Y - 1e52), when the real scale is up to a max in the billions. When I plot without the transformation (that is, no trans="log10", things work fine; the dollar label is applied, and the data is correct.
Here is an example of the code I am running that produces the issue (data cannot be shared). And again, dropping the transformation (trans="log10"), everything works fine so it is not a data issue, per se. Also note the data does not include NAs.
test_df%>%
ggplot()+
geom_col(aes(x=name, y= dollar_value, fill=factor_variable))+
labs(title = "main title",
x = "",
y= "Dollars (log10)",
fill = "Factor Variable Name")+
scale_y_continuous(trans="log10", labels=scales::dollar)+
theme_classic2()
Any ideas what is happening here?