# Tag Info

## Hot answers tagged ggplot2

7

Simulate some data: library(ggplot2) library(purrr) library(ggthemes) days <- seq(as.Date("2015-08-01"), as.Date("2015-08-31"), by="1 day") hours <- sprintf("%02d", 0:23) map_df(days, function(x) { map_df(hours, function(y) { data.frame(day=x, hour=y, val=sample(2500, 1), stringsAsFactors=FALSE) }) }) -> df Check it: ggplot(df, aes(x=...

4

There is one big economic difference between the two: ggplot2 is an open source package for an open source programming language. On the contrary Tableau is a proprietary software. That might be a dependency that you might not want to risk, e.g. you do everything in Tableau but then the license gets more expensive and your organization does not want to spend ...

4

Well, many months have been passed from this help request. I write this answer to my own request in order to share my experience. I learned ggplot2 and then ggvis as well as Shiny. Shiny can work with both of them, but I found ggvis more structured and lucid comparing to ggplot2. Something which is expectable as the former is being developed based on the ...

4

If I understand right your question, you are looking to plot selected numerical columns against a selected categorical column of your dataset, am I right ? If so, you can have the use of dplyr, tidyr and ggplot2 packages to achieve this. Starting with this dataframe: id num1 num2 num3 cat cat2 1 C -0.48892284 1.417909 2.8884577 a ...

4

I don't know what you mean by "with linear model" in the title, but here's code that generates a toy dataset and replicates your plot. library(tidyverse) x<-crossing(year=paste("Year", 1:3), avg=c("Above 4.0", "Below 4.0")) x$dat<-replicate(6, tibble(wrkday=runif(100, 1000, 2000))) x %>% unnest(dat) %>% ggplot(aes(dat)) + geom_histogram(... 3 What you can do is creating another dataset with the mean and mean±stdev grouped by Tier. Then you can use that in geom_hline and ggplot will pick up facets from Tier. See below; library(dplyr) library(tidyr) library(ggplot2) Interactions %>% group_by(Tier) %>% summarise(mean = mean(TotalInteractions), mean-stdev = sum(mean(... 3 Two alternative way are a density plot for each hour and level plot of hour and factorized value. I'm showing ganarated data with two different unified distribution (for day and night hours) Densityplot library(lattice) xy <- densityplot(~ value, groups = hour , plot.points=FALSE, data = df, scales=list(x=list(rot=90, cex= .9 ),y=list(cex=.9)),... 3 Change Year to a factor and add group=1: g <- ggplot(Total_Emmisssions,aes(x=factor(Year), y=Emissions, colour=Type, group=1)) you can leave the rest the same (you'll also prbly want to change the xlab). 3 something like this might work: library(plyr) # initialize All_Data around here dlply(All_Data, 'Identifier', function(dataSubset) { g <- ggplot(dataSubset) + geom_point(mapping =aes(SampleDate, Total.Result)) + ylim(0,20000) file_name <- paste0("Scatter_", unique(dataSubset$Identifier), ".tiff", sep="") ggsave(file_name,g) }) (I didn't test ...

2

Use a custom panel function in which the density is estimated (e.g. using MASS::kde2d()): library("lattice") library("MASS") set.seed(1); dat <- data.frame(x=rnorm(100), y=rt(100, 5)) xyplot(y~x, data=dat, panel=function(x, y, ...) { dens <- kde2d(x=dat$x, y=dat$y, n=50) tmp <- data.frame(x=dens$x, ... 2 Clearly there's no way to have the names of the drugs. Assuming the relation between the two columns is important, a scatter plot with units prescribed as X and number of patients as Y might work. You could even add the name of the drug for a few isolated points. Transparency/opacity can be used to show the dense areas. In case the relation between the ... 2 Try adding theme to your plot layout So: library("reshape2") library("purrr") library("dplyr") library("dendextend") dendro <- as.dendrogram(aggl.clust.c) dendro.col <- dendro %>% set("branches_k_color", k = 5, value = c("darkslategray", "darkslategray4", "darkslategray3&... 2 You can either reshape the data into long format (after joining the two datasets) and use geom_col once, or have two geoms as you have in your question. However, the latter needs some variation to have the aes in geom_col and not in ggplot. Below, I have an example with mpg dataset, illustrating the two options (except the joining). I also included an ... 2 Step 1: Changing dates to years First you can change your column of dates (Order_Date) to simply years by using this formula: > salesdata$Order_Date = format(salesdata\$Order_Date, "%Y") This will give your Order Dates just the year the sales was done in. Step 2: Summarizing your sales data After this you can create a vector with the summarizations of ...

1

You could try quantile regression using a "generalised additive" model. With R you could use the qgam package, I guess. What you need to do is to estimate a model for upper/lower values of the distribution. The figure below shows a plot from the qgam vignette linked above.

1

Two things before the answer: Please always produce a sample dataframe with dput() As this is totally coding based, this might be more suitable for StackOverflow Proceeding with the answer #Load the libraries library(tidyverse) library(reshape2) #Create the data frame JUL_REV <- c(100,2000,3000,340) AUG_REV <- c(2032,2103,3002,300) REGION <- c('...

1

Would something like this work? I simply add an extra column that indicates the row number (which is later used as the x-axis) to make sure all values are displayed as a new point instead of plotting on top of each other for the same day. I then specifiy the custom x ticks and labels by selecting the first row for each day and get the row number (which ...

1

There's no way to have a complete summary of a large dataset like this, you have to analyze what can be relevant, decompose into more specific pieces of information and then find the best way to visualize each specific part on its own. The first thing would be to plot the distribution of this parameter of interest across subjects and/or observations. If you ...

1

The function you are looking for is gather from the tidyr package. This function takes a wide data.frame and makes it a long data.frame. gather is easy to use: library(dplyr) library(tidyr) # Building a sample data.frame like your example data. df <- data.frame(Boardgame = c("Game1", "Game2", "Game3", "Game4", "Game5"), categorie1 = c("...

1

Whenever you give percentages, you need a very clear statement about the denominator. I can deduce it here, but in general one could give the percentage of bike only accidents of all accidents in the medium sized cities or the percentage of bike only accidents happening in medium sized cities of all bike-only accidents. Or... The kind of percentage (or ...

1

Looking into so many plots may miss the bigger picture. We should keep the initial plot in "One Consolidated plot" e.g. Can add few other consolidated views - Pie on aggregated data on region and Vehicle

1

I finally figured out something that works: plot_list = list() for (i in Monitoring_Locations){ p = ggplot(All_Data) +geom_point(aes(SampleDate, Total.Result)) plot_list[[i]] = p } for (i in Monitoring_Locations) { file_name = paste("Scatter", i, ".tiff", sep="") tiff(file_name) print(plot_list[[i]]) dev.off() } The only ...

1

It is in order, but not in the order that you want. It is currently treating the indices as a string. To get your desired index as numerics, here are some codes that hopefully can help you. > c = c("1", "2", "13") > c = sort(c) > c [1] "1" "13" "2" > c = strtoi(c) > c [1] 1 13 2 > sort(c) [1] 1 2 13

1

From further research I've discovered that the frequency is given by the index of the FFT multiplied by the sampling rate and divided by the size of the array. And the amplitude is the magnitude of the complex number. So the full code for such a plot would be as follows # X is some set of Wait times between spikes, below is just an example X <- c(56, 3, ...

1

This doesn't answer your Tableau questions, but I can say a few things about ggplot2. ggplot2's has reasonable defaults but nearly everything about the plots can be changed to make the results more clean aesthetically. One package I use all the time is called 'cowplot': https://cran.r-project.org/web/packages/cowplot/vignettes/introduction.html ggplot2 also ...

1

Plotly is R package for creating interactive web-based graphs via plotly's JavaScript graphing library, plotly.js. The plotly R libary contains the ggplotly function , which will convert ggplot2 figures into a Plotly object. If you are still getting the recommendation even after installing it, it seems it was not properly installed. Please refer the below ...

1

I would separate the creation of the data from the plotting operation, if I were you. ggplot2::facet_wrap allows you to plot each of the cumulative distributions in each own panel. Here is how I would do it. pgammaX <- function(x) pgamma(x, shape = 64.57849, scale = 0.08854802) Gamma <- pgammaX(seq(from=4, to = 8, by = 0.1)) Normal <- pnorm(seq(...

1

You could give the plotlypackage a try. You basically code up the plot you want first with ggplot2 and then call ggplotly() at the end, which will render an interactive version of it. You get zooming in on mouse selection for example and labels of points on hover. It has a pretty extensive documentation too. I can try and help you out with a specific example ...

1

Time flies! After 2years of working experience, now I answer to my own question with better understanding of Shiny,R, and interactive visualization. The Plotly is by far the best answer. It can be easily used by ggplotly() conversion of ggplot2 static plots, or directly by learning the logic behind the Plotly functions. The latter case is suggested for ...

Only top voted, non community-wiki answers of a minimum length are eligible