Hot answers tagged

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

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 ...


3

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

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 ...


3

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 ...


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).


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

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 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 ...


1

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 ...


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 ...


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