我的情节中的图例偶尔会将尺寸变量的值显示为1e + 05。我的观众不太可能立即知道这与100000相同,所以我希望传说中说100000,80000,60000,40000,20000。无论如何在ggplot中控制这个指数功能?
我在示例代码中包含了一些虚假数据和一个示例图像。您必须多次重新运行代码才能使其重现显示的问题。
library(data.table)
dt <- data.table(DATE = c("2014-03-01", "2014-04-01", "2014-05-01",
"2014-06-01", "2014-07-01", "2014-08-01",
"2014-09-01", "2014-10-01", "2014-11-01",
"2014-12-01", "2015-01-01", "2015-02-01"
, "2015-03-01"),
TOTAL_VOLUME = rnorm(n = 13, mean = 53000, sd = 25000),
NON_CONFORMING_VOLUME = rnorm(n = 13, mean = 8400, sd = 6000))
# Switch any negatives to positive
dt$NON_CONFORMING_VOLUME <- abs(dt$NON_CONFORMING_VOLUME)
# Could have NON_CONFORMING > TOTAL, set arbitrarily to 30% of total
dt$NON_CONFORMING_VOLUME <- ifelse(dt$NON_CONFORMING_VOLUME > dt$TOTAL_VOLUME,
dt$TOTAL_VOLUME * .3, dt$NON_CONFORMING_VOLUME)
dt$PERCENT_NON_CONFORMING <- dt$NON_CONFORMING_VOLUME / dt$TOTAL_VOLUME * 100
p1 <- ggplot(data = dt, aes(x = DATE,
y = PERCENT_NON_CONFORMING,
size = TOTAL_VOLUME)) +
geom_point() +
theme(legend.position="bottom") +
ggtitle("Percent Non-Conforming by Month") +
labs(x = "Month", y = "% Non-Conforming") +
geom_hline(yintercept = mean(dt$PERCENT_NON_CONFORMING),
colour = "darkorange")
plot(p1)
答案 0 :(得分:1)
我很惊讶,在运行你的代码时,我没有得到科学记数法,我得到20000,40000等等。也就是说,修复是在大小范围内指定labels
函数,scales
包具有很好的选项。对于这些数据,逗号格式可能最好,那么你将得到20,000,40,000 ......
library(scales)
plot(p1 + scale_size_continuous(labels = comma))