Posts

Showing posts with the label ggplot2

Reorder not working in ggplot with my current data frame

Image
Reorder not working in ggplot with my current data frame I'm currently trying to make my own graphical timeline like the one at the bottom of this page. I scraped the table from that link using the rvest package and cleaned it up. Here is my code: library(tidyverse) library(rvest) library(ggthemes) library(lubridate) URL <- "https://en.wikipedia.org/wiki/List_of_Justices_of_the_Supreme_Court_of_the_United_States" justices <- URL %>% read_html %>% html_node("table.wikitable") %>% html_table(fill = TRUE) %>% data.frame() # Removes weird row at bottom of the table n <- nrow(justices) justices <- justices[1:(n - 1), ] # Separating the information I want justices <- justices %>% separate(Justice.2, into = c("name","year"), sep = "(") %>% separate(Tenure, into = c("start", "end"), sep = "n–") %>% separate(end, into = c("end", "reason"), se...

Control time-series axis label and color in R stacked bar

Image
Control time-series axis label and color in R stacked bar I'm trying to plot a stacked bar. Its work but still there are some function that I don't understand e.g, what xts do? Am I using all the library I've load? Replacing the axis label, its work with original data, but not with melted data (data was melted for producing stacked bar, because I didn't find any other ways to produced stacked bar using data.frame) . I also want to use monochrome color for this stacked bar. I try replacing 'fill = variable' to 'fill = c("orange", "blue", "green")' just to try, its not working. Kindly help.. Thank you.. library(ggplot2) library(xts) library(reshape2) library(lubridate) library(zoo) setwd("C:/Users/Hp/Documents/yr") data1 <- read.csv("yr1983.csv", head = TRUE, stringsAsFactors = FALSE) data1$Date <- dmy(data1$Date) #data1 <- xts(x = data1[,-1], order.by = data1[,1]) head(data1) Date Inla...

Facet Wrap in r barplot and line

Image
Facet Wrap in r barplot and line I'm dealing with R and ggplot and I have this dataframe: R ggplot > Results V NetStateCosts DeltaCosts CostPerTon 1 BAU 6.071476 -2.060885e-04 0.0000 2 ENT 56.549041 -5.165512e+01 512.2071 3 FIN -126.879230 6.180334e+01 -277.3276 4 TWC -24.398330 1.591942e+01 -240.2432 5 FITAX -118.786530 2.514306e+01 -210.3841 6 FITWC -214.627979 1.210538e+02 -383.4240 7 TWCTAX 26.490005 -3.510108e+01 240.9295` I'm trying to plot a barplot for the variables NetStateCosts and DeltaCosts (column V represents different scenarios) but then I want to add a second graph, using facet wrap, that plot over the other one a line built using CostPerTons y value (but x is the same (V column)). barplot NetStateCosts DeltaCosts CostPerTons Final plot should be something like this However I'm struggling using facet_wrap to do that. Any ideas? facet_wrap Here is what I was able to do but I don't kno...

How to plot a performance/ rate graph ? in r

Image
How to plot a performance/ rate graph ? in r I am trying to plot a graph depicting the performance of the best selling items, moderate selling items and the least selling items and they show which particular brand they belong to and their respective sub_category + category Raw Data : sraw <- structure(list(Date = c("2018-02-28", "2018-02-28", "2018-02-28", "2018-02-28", "2018-02-28", "2018-02-28"), Category = c("Bakery ", "Household ", "Household ", "Personal care", "Personal care", "Breakfast "), Sub_Category = c("Wafers ", "laundry ", "Pet Care", "Womens grooming ", "Womens grooming ", "Instant food"), Product = c("strawbery", "washing powder ", "Cat food ", "sanitary pad ", "sanitary pad ", "Noodles "), Brand = c("NO BRAND", "whe...

ggplot barplot knitted with R Markdown

Image
ggplot barplot knitted with R Markdown Problem: The labels of the y-axis of this plot are too close too each other. Question: How can I increase the spacing between labels? Make the plot bigger, make the font smaller, show fewer labels. Not rotating your xaxis labels will give you a smidgeon more space. – Richard Telford Jun 29 at 10:37 @RichardTelford, how can I make the plot bigger? Ideally I can make the plot vertically longer, do you know how? – delcast Jun 29 at 10:41 you can set the fig.height in the chunk options – Richard Telford Jun 29 at 10:54 ...

Default colors in ggplot2 for extended legend labels

Default colors in ggplot2 for extended legend labels I wanted to refer to the question: Force ggplot legend to show all categories when no values are present I'm in a similar situation, but I would like the colors to be the default. How should I do this? ADDED: I looked more closely and it turned out that, unfortunately, the labels were changed. Raw data looks like this: > str(mj) 'data.frame': 4393 obs. of 22 variables: $ OS_Gatunek : Factor w/ 5 levels "Taraxacum ancistrolobum",..: 1 1 1 1 1 1 1 1 1 1 ... $ PH_CreateDate : Factor w/ 15 levels "2016-04-06","2016-04-19",..: 2 2 2 2 2 2 2 2 2 2 ... $ L_Ksztalt : Factor w/ 3 levels "lancetowaty",..: 3 2 3 3 2 2 3 3 2 3 ... $ L_Symetria : Factor w/ 3 levels "duża","mała",..: 1 3 1 3 2 3 2 2 2 1 ... $ L_Sfaldowanie : Factor w/ 2 levels "brak","obecne": 1 1 1 2 2 1 1 2 1 1 ... $ KS_Ksz : Factor w/ 3 leve...