I have a chart with countries that have different associated percentages.
One of the countries has a very large percentage, the rest very small. I create a chart in ggplot and then convert it to a plotly object with ggplotly():
However, I then have the problem of the other country percentages being so small that they're not really visually useful, and some of them also do not display tooltips if hovered over. So, I decided to convert the x-axis to a log10 scale, but:
This is obviously incorrect. How can I convert the x-axis correctly into a logarithmic scale?
I will admit that I'm not super familiar with log/log10, so any help would be appreciated.
Reproducible code:
df <- data.frame(
country = c("Australia", "United Kingdom", "United States", "China", "Ukraine", "New Zealand"),
percentage = c(0.98, 0.002, 0.005, 0.007, 0.003, 0.003)
)
# Without logarithmic transformation
x <- df %>% ggplot(
aes(
x = percentage,
y = reorder(country, -percentage),
fill = country
)
) + geom_bar(stat = "identity")
ggplotly(x)
# With logarithmic transformation
x <- df %>% ggplot(
aes(
x = percentage,
y = reorder(country, -percentage),
fill = country
)
) +
geom_bar(stat = "identity") +
scale_x_log10()
ggplotly(x)


