Convert from scientific notation to decimal with ggplot

I am trying to build some test data (show at the end of this post) using ggplot using the following command:

 options(scipen=20) ggplot(testData,aes(x=Group.1, y=x), format(scientific=FALSE)) + scale_x_discrete(name="Test", formatter=comma) + geom_bar() 

The plot is generated quite well, but the x axis is in scientific notation (as in the test data), how could I display it in decimal? (As shown in the command, I have already tried the scipen option and various formatting options - as suggested in other posts on this site)

My test data:

 > str(testData) 'data.frame': 5 obs. of 2 variables: $ Group.1: Factor w/ 5 levels "(1.3e+03,1.5e+03]",..: 1 2 3 4 5 $ x : num 80000 94000 86000 112000 98000 > testData Group.1 x 1 (1.3e+03,1.5e+03] 80000 2 (1.5e+03,1.7e+03] 94000 3 (1.7e+03,1.9e+03] 86000 4 (1.9e+03,2.1e+03] 112000 5 (2.1e+03,2.3e+03] 98000 > dput(testData) structure(list(Group.1 = structure(1:5, .Label = c("(1.3e+03,1.5e+03]", "(1.5e+03,1.7e+03]", "(1.7e+03,1.9e+03]", "(1.9e+03,2.1e+03]", "(2.1e+03,2.3e+03]"), class = "factor"), x = c(80000, 94000, 86000, 112000, 98000)), .Names = c("Group.1", "x"), row.names = c(NA, -5L), class = "data.frame") 

TestData generation:

 testData <- aggregate(as.numeric(as.character(housing7$PRICE)), by=list(cut(as.numeric(as.character(housing7$SIZE)), breaks=5)), FUN=mean) 
+6
source share
1 answer

Once the labels of your factor are stored in scientific notation, it is not easy to return to normal notation.

Since you used cut to create this factor, you can change the number of digits used in the label with the argument dig.lab . For instance:

 testData <- aggregate(as.numeric(as.character(housing7$PRICE)), by=list(cut(as.numeric(as.character(housing7$SIZE)), breaks=5,dig.lab=6)), FUN=mean) 
+6
source

Source: https://habr.com/ru/post/919362/


All Articles