developer tip

R이 축약 된 축 레이블 플로팅을 중지하도록 강제합니다 (예 : ggplot2의 1e + 00).

optionbox 2020. 10. 9. 11:07
반응형

R이 축약 된 축 레이블 플로팅을 중지하도록 강제합니다 (예 : ggplot2의 1e + 00).


ggplot2에서 축 레이블이 축약되는 것을 어떻게 막을 수 1e+00, 1e+01있습니까? 예를 들어 일단 플로팅 된 x 축을 따라? 이상적으로는 R이 실제 값을 표시하도록 강제하고 싶습니다 1,10.

많은 도움을 주셔서 감사합니다.


나는 당신이 이것을 찾고 있다고 생각합니다.

require(ggplot2)
df <- data.frame(x=seq(1, 1e9, length.out=100), y=sample(100))
# displays x-axis in scientific notation
p  <- ggplot(data = df, aes(x=x, y=y)) + geom_line() + geom_point()
p

# displays as you require
require(scales)
p + scale_x_continuous(labels = comma)

다음과 같은 것을 시도 했습니까?

options(scipen=10000)

플로팅하기 전에?


@Arun이 만든 업데이트에 대한 업데이트입니다. 오늘 시도했지만 실제로 작동하지 않았기 때문에

+ scale_x_continuous(labels = scales::comma)

보다 일반적인 솔루션으로 scales::format_format과학적 표기법을 제거하는 데 사용할 수 있습니다 . 또한 scales::comma쉼표로만 구분하는 것과 달리 레이블을 정확히 표시 할 방법을 제어 할 수 있습니다 .

예를 들면 :

require(ggplot2)
require(scales)
df <- data.frame(x=seq(1, 1e9, length.out=100), y=sample(100))

# Here we define spaces as the big separator
point <- format_format(big.mark = " ", decimal.mark = ",", scientific = FALSE)

# Plot it
p  <- ggplot(data = df, aes(x=x, y=y)) + geom_line() + geom_point()
p + scale_x_continuous(labels = point)

참고 URL : https://stackoverflow.com/questions/14563989/force-r-to-stop-plotting-abbreviated-axis-labels-eg-1e00-in-ggplot2

반응형