我一直在玩一个闪亮的应用程序,以可视化来自国际货币基金组织数据库的数据。
应用程序中的一个标签包括使用geom_point()
将两个指示符相对于另一个指示符。
我认为以对数比例绘制数据可能有助于可视化,因为数据分布经常偏斜。
一方面,对于严格为正的值,不会遇到任何问题。 另一方面,由于某些指标以百分比变化衡量,可能为负,因此ggplot只是从图中排除了这些值(考虑到负值的对数未定义的事实,这是有道理的)。
听起来像是一个奇怪的问题,但这是:
有没有一种方法可以显示负值,同时仍以对数刻度绘制轴?
请查看以下代码:
output$interact1 <- renderPlot({
x <- ggplot(filter(testplot, Year == input$y),
aes_string(x = input$indicator, y = input$indicator2))
x + geom_jitter(aes_string( col = "Continent", size = "Population")) +
scale_size_continuous(breaks = c(0,5,50,100,200,1000)) +
theme(legend.position = "bottom") +
scale_x_log10() +
scale_y_log10() +
geom_smooth(aes_string(input$indicator, input$indicator2),
method = "loess", col = "black") +
geom_smooth(method = "lm", col = "red", show.legend = F) +
ylab(gsub("_"," ",input$indicator2)) +
xlab(gsub("_", " ", input$indicator)) +
labs(caption = paste(gsub("_"," ",input$indicator2),
"vs.",
gsub("_", " ", input$indicator)))})
下面的屏幕快照也可能有助于理解我在这里试图做什么:
编辑: