![]() Library ( plotly ) library ( LaCroixColoR ) library ( dplyr ) european_leaders % mutate ( stint_start = as.Date ( stint_start ), stint_end = as.Date ( stint_end ), median_x = as.Date ( median_x ), left_right = as.character ( left_right )) p <- ggplot ( european_leaders, aes ( xmin = stint_start, xmax = stint_end, ymin = vert_min, ymax = vert_max, fill = left_right )) + geom_rect ( colour = "white", size = 0.1 ) + geom_text ( aes ( x = median_x, y = median_y, size = size, label = pm_name, #all names of separate variables text = paste ( party_name_english, " (", country_name, ")", sep = "" ))) + scale_fill_manual ( values = lacroix_palette ( "PassionFruit", type = "continuous", n = 8 )) + #matches left/right colours labs ( title = "Timeline of European leaders since 2000", x = "year", y = "", fill = "Party's \nleft-right \nscore", size = NULL ) + theme ( = element_blank (), #y-axis doesn't have actual values no need for labels axis.ticks. unemployed (x 1000)" ) fig <- ggplotly ( p ) fig Library ( plotly ) library ( dplyr ) df % mutate ( median_x = start + floor (( end - start ) / 2 )) p <- ggplot ( economics, aes ( x = date, y = unemploy )) + geom_rect ( data = df, aes ( NULL, NULL, xmin = start, xmax = end, fill = party ), ymin = 0, ymax = 16000, colour = "white", size = 0.5, alpha = 0.2 ) + scale_fill_manual ( values = c ( "R" = "red", "D" = "blue" )) + geom_line () + geom_text ( data = df, aes ( x = median_x, y = 3000, label = name ), size = 3 ) + labs ( title = "Unemmployment numbers since 1967", y = "No. This is for illutrustive purposes, using a simple case and a default dataset. ![]() library (ggplot2) library (grid) make a plot with blue background p <- ggplot (iris, aes (Sepal.Length, Sepal.Width)) + geompoint () + theme (plot.background elementrect (fill 'C4E7FF'), panel. An important note: the President does not control economic policy, something that this graph hopefully makes apparent. The Extending ggplot2 vignette is probably a good place to start as far as making your own extension goes. ![]() (This dataset comes with R.) We use geom_rect to shade the background according to the President's party. This line graph shows the unemployment number in the United States every month, beginning in July 1967. Fill refers to the colour of the rectangle, colour refers to the border, and size refers to the border width. Geom_rect is defined by its four sides (xmin, xmax, ymin, ymax), which are all included in the dataset. You can use the following basic syntax to shade a particular area in a plot in ggplot2: ggplot(df, aes(xx, yy)) + geompoint() + annotate(' rect ', xmin 3, xmax 5, ymin 3, ymax 7, alpha.2, fill' red ') This particular example shades the area between the x-values of 3 and 5 and the y-values of 3 and 7. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials. Plotly is a free and open-source graphing library for R.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |