![]() ^ 2 ) # Secondary axes work for date and datetime scales too: df <- ame ( dx = seq ( as.POSIXct ( " 12:00:00", tz = "UTC" ), length.out = 10, by = "4 hour" ), price = seq ( 20, 200000, length.out = 10 ) ) # This may useful for labelling different time scales in the same plot ggplot ( df, aes (x = dx, y = price ) ) + geom_line ( ) + scale_x_datetime ( "Date", date_labels = "%b %d", date_breaks = "6 hour", sec.axis = dup_axis ( name = "Time of Day", labels = scales :: time_format ( "%I %p" ) ) ) # or to transform axes for different timezones ggplot ( df, aes (x = dx, y = price ) ) + geom_line ( ) + scale_x_datetime ( " GMT", date_labels = "%b %d %I %p", sec.axis = sec_axis ( ~. ![]() + 10, name = derive ( ) ) ) # Duplicate the primary axis p + scale_y_continuous (sec.axis = dup_axis ( ) ) # You can pass in a formula as a shorthand p + scale_y_continuous (sec.axis = ~. You can interpret this code as follows: create a ggplot-object (a graph) on the basis of the data(frame) yourdata that you supply, and more specifically, use. + 10 ) ) # Inherit the name from the primary axis p + scale_y_continuous ( "Miles/gallon", sec.axis = sec_axis ( ~. Call ggplot2 () function and put first parameter ‘data’ and then set the aesthetics function ‘aes ()’. it has to be a data frame, and it needs one numeric and one categorical variable. 8.1 Plot and axis titles ggplot(mpg, aes(displ, hwy)) + geompoint(aes(colour factor(cyl))) + labs( x Engine displacement (litres), y Highway. P <- ggplot ( mtcars, aes ( cyl, mpg ) ) + geom_point ( ) # Create a simple secondary axis p + scale_y_continuous (sec.axis = sec_axis ( ~. Syntax: ggtitle (Title For Plot) Later to add this title to the plot we simply have to set margins.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |