Transforming table to format for stacked bar chart - r

I've got a data frame in R that looks like this
URL TTFB StartRender FullyLoaded
http://news.bbc.co.uk/ 500 750 3000
and I want to plot a stacked bar chart from it where each segment of the bar is as follows:
TTFB
StartRender - TTFB
FullyLoaded - StartRender
I'm having a real problem understanding how I need to transform the data to be able to plot the column for each URL (or even what the data needs to look like)

Stacked bar charts are not good data visualizations. Much better to use a grouped Cleveland dot plot. In R these are available with the dotchart command in the graphics package.
The problem with stacked bar charts is that it is hard to estimate the proportions except for the bottom of the stack.

Faceting provides a good alternative to stacking, and can be done fairly easily in R using ggplot2

Related

Overlay Plots : Time Series - Different Frequencies (Lines over Bars) [ggplot2]

My question is about overlaying plots of different x and y scales .The raw data is out of a public weather database in New Zealand called CliFlo, managed by NIWA. I'm not prepared to copy the data for an example because of copyright protections.
I want to reproduce the types of graphs they offer at a fee, shown on this web page. Take the Rainfall graph. There is a cumulative rainfall line graph overlayed on top of a monthly rainfall bar graph. I can generate each graph separately using ggplot2, but I can't find a good way to overlay them like in the example. I've found the gridExtra package to let me print them side-by-side, and I've come across the magick package that might let me do the job, but I'm not sure on how to get the plots lined up properly and how to use the magick package properly. Can anybody help me out on this?
Should I try to scale the month bars to fit the daily line graph but make them spaced out and thicker so they look like months, or would it be easier to use the magick package somehow?
I'd attach an image of what I have so far, but I'm new to this website and it won't let me yet.

How to draw pie of pie or bar of bar charts in R (using ggplot2)? [duplicate]

I know it is possible to create such double pie charts in excel like this:
http://chandoo.org/wp/2009/12/02/group-small-slices-in-pie-charts/
but can SPSS or R do this also?
In relation to R:
The answer to the title question is "yes" ... see ?pie
As for the second question, the one in the body - it would be possible but would involve some coding. You'd have to draw two pie charts side by side (which could be managed with two calls to pie) and use segments or arrows (and text if necessary) to do the additional components of the plot.
Here's a rough example:
That required the fig argument of par to get them side-by-side.
(That example required a little fiddling to get right, but it would be possible to write a function to automate the details.)
The main issue I can see would be 'why on earth would you do it?' -- pie charts are a poor way of conveying information of this form. There are alternatives that result in much better ability to distinguish values, and less bias (such as what you get when comparing nearly horizontal vs nearly vertical slices).

Plotting vertical bars and series (x= y=) together using SAS

Here is a graphical output that I'm trying to mimic. I want a series AND vertical bars plotted simultaneously
However the SAS has a compatibility issue with plotting series and vbar together. Is there a way to plot my data as above?
Take a look at the V9.2 GBarLine example at:
http://robslink.com/SAS/democd30/aaaindex.htm
If you have SAS version 9.2 or above you should be fine.

R: How to overlay pie charts on 'dots' in a scatterplot in R

Using R I would like to replace the points in a 2d scatter plot by a pie chart displaying additional values.
The rational behind is that I have time series data for hundreds of elements (proteins) derived from a biological experiment monitored for 4 conditions. I would like to plot the elements (categorial data) on the y axis and occurrence of a event in time on the x axis. To visualize the relative occurrence between the 4 conditions I would like to visualize this in form of a pie chart or doughnut chart overplayed onto the respective point in the scatter plot.
The overall data density is low so overlapping won't be an issue.
Is this possible in R?
I was thinking of using a manual scale in ggplot2 but could not figure out how to define a pie chart as a scale.
Also of interest would be how to best cluster this data and sort it accordingly.
Yes. pieGlyph() is one ready-to-go function from the Rgraphviz package.
Also, I would check out this Q/A for how to do things like this more generally:
How to fill a single 'pch' point on the plot with two-colours?
Especially check out ?my.symbols from the TeachingDemos package.
Lastly, in regards to ggplot2, you should check out this blog post about possible upcoming features:
http://blog.revolutionanalytics.com/2011/10/ggplot2-for-big-data.html
See also Paul Murrell. Integrating grid graphics output with base graphics output. R News, 3(2):7-12, October 2003. http://www.r-project.org/doc/Rnews/Rnews_2003-2.pdf
The code on pp 10-11 sets up the main plot axes, labels and legend, and then opens a series of smaller windows centered at each individual point on the plot and plots a small graph in each window. I've tried pie charts, mosaics and barplots, but the method is not limited to these types.

How does one plot a 3D stacked histogram in R?

I want to plot stacked histograms in R; i.e. stack individual histograms in the third dimension.
thank you all for your suggestions, especially the one by Shane.
#hadley, I agree with your points, however, my situation is different: the main point I'm trying to convey by plotting four stacked histograms is that the tails vary significantly....the part that will get obscured is of no consequence in the data I'm presenting....also, being able to read the frequency axis is also not important since I'll be plotting the relative frequencies...
One doesn't. This is a terrible display of data because the front histograms obscure the rear histograms and the perspective makes it just about impossible to read the values off the y-axis.
You could try using either rgl (see here) or 3dscatterplot (as in this example). Lattice also supports this:
library(lattice)
library(latticeExtra)
?panel.3dbars
You can see an example of this on the Learnr blog.
I don't believe that's technically a stacked histogram (a stacked histogram stacks the bars on top of each other). Moreover, a different kind of histogram could be more informative: look at the ggplot2 the documentation here for some examples.
hist_cut <- ggplot(diamonds, aes(x=price, fill=cut))
hist_cut + geom_bar() # defaults to stacking
Another option is to use latticing instead, with facet_wrap in ggplot2 (see this post as an example).

Resources