In GGPLOT2 Hoe kan ik axis-labels stoppen die worden afgekort – b.v. 1e+00, 1e+01
Langs de X-as is eenmaal geplot? Idealiter wil ik dwing R om de werkelijke waarden weer te geven die in dit geval 1,10
zou zijn.
Elke hulp opgewaardeerd.
Antwoord 1, Autoriteit 100%
Ik denk dat u hiernaar op zoek bent:
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)
Antwoord 2, Autoriteit 47%
Heb je iets geprobeerd als:
options(scipen=10000)
voor het plotten?
Antwoord 3, Autoriteit 28%
Gewoon een update van wat @arun maakte, omdat ik het vandaag heb geprobeerd en het niet werkte omdat het geactualiseerd was om
+ scale_x_continuous(labels = scales::comma)
Antwoord 4, Autoriteit 13%
Als een meer algemene oplossing, kunt u scales::format_format
gebruiken om de wetenschappelijke notatie te verwijderen. Dit geeft u ook veel controle over hoe u wilt dat uw labels worden weergegeven, in tegenstelling tot scales::comma
, die alleen komma-scheidingen van de ordes van grootte.
Bijvoorbeeld:
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)
Antwoord 5, Autoriteit 7%
Er is een oplossing die geen schalenbibliotheek vereist.
U kunt het proberen:
# To deactivate scientific notation on y-axis:
p + scale_y_continuous(labels = function(x) format(x, scientific = FALSE))
# To activate scientific notation on y-axis:
p + scale_y_continuous(labels = function(x) format(x, scientific = TRUE))
# To deactivate scientific notation on x-axis:
p + scale_x_continuous(labels = function(x) format(x, scientific = FALSE))
# To activate scientific notation on x-axis:
p + scale_x_continuous(labels = function(x) format(x, scientific = TRUE))
Antwoord 6, Autoriteit 3%
Uitbreiding van de oorspronkelijke vraag om zowel fracties te omvatten, d.w.z. 1, 0,1, 0,01, 0,001 enz. En vermijd trailing nullen
p + scale_x_continuous(labels = function(x) sprintf("%g", x))
Antwoord 7
is niet de eenvoudigste algemene oplossing om de straf in te stellen die r gebruikt voor wetenschappelijke notatie hoger?
I.E Stel scipen()
in op een nummer waarmee u zich op uw gemak bent.
b.v. Als het maximum van uw as op de diagramen waarschijnlijk 100 000 is, zal het instellen van scipen(200000)
ervoor zorgen dat R (en GGPLOT) standaard notatie voor alle nummers onder 200000 zal gebruiken en er geen vereiste is om toe te voegen elke regels aan de GGPLOT-functie.