Hierarchical bar charts in r - r

I'm working on a visualization project in R and thought of creating bar charts for hierarchical data (states with constituencies in it, each constituency possessing a numeric value).
I came across this web page (https://observablehq.com/#d3/hierarchical-bar-chart) which implements exactly this using library "d3" but for JavaScript.
Is there any similar library in R to do this?

I also had similar question before! But I couldn't find any package or code online that does the same thing in R, the closest thing I found was "r2d3" package which allows you to run javascript in R.
So by leveraging the "r2d3" package, I was able to replicate it and put it into a function call "hbar", you can directly source it from my github with the code below:
source("https://raw.githubusercontent.com/JohnnyPeng123/hierarchical_bar_chart-/master/hbar.r")
For more details and use case please follow the link below:
https://github.com/JohnnyPeng123/hierarchical_bar_chart-
Let me know if you need any help in terms of using this function.

You can use ggplot.
If you need more help, please share a reproductive example.

Related

How to make a function like swirl() in R?

I was interested in generating a course like "swirl" in R. So a course that would interact with the user upon running it. I wanted to start from scratch and I am not sure on how to do this. Is there any specific documentation for this technique or does it have a specific name I could look for?
Maybe learnr with rmarkdown?
With learnr you can create rmarkdown docs that can run code, show results, preserve code and results.

"imagesc" function belongs to which packages and libraries in r?

After forming the matrix( which is my resultant image ) from certain data I am trying to display the image using the "imagesc" in r. The same thing I already had done in Matlab. To do the same in r I found out "imagesc" in r. but when I use this function it is showing the following error message
No documentation for ‘imagesc’ in specified packages and libraries:
you could try ‘??imagesc’
Even I already incorporated
library(R.matlab)
please help me to resolve the issue? I am a beginner in r programming.
You are looking for the function imagesc in the wrong package.
The package R.matlab doesn't have such function (see R.matlab).
You can find it in the matlab package, though.
So just do:
install.packages("matlab")
library(matlab)
and you'll be good to go with imagesc.
That said, if your task is going to be a recurrent one, I think it's a good idea to use native R solutions, instead of Matlab's. In such case, you may want to check ggplot2::geom_tile.
Check this image, for instance:

How to import fundamentals for stocks by using Quandl package

I'm trying to import fundamentals for stocks by using Quandl package,I pulled some data by using this line of code:
mydata <-Quandl("WIKI/AAPL", collapse="quarterly")
However, I don't understend how can I get fundamentals data and not just the price data.
Any Idea how to do that? Also, Is there a way to pull all fundamentals with the same line?
On this site you find all the fundamentals:
http://www.quandl.com/c/stocks/aapl. Just click on the figure (quaterly/anualy) and you will be directed to a page with the data. There is an R button on the right. Clicking it will give you the R-Code.
Example:
Gross-Profit: http://www.quandl.com/SEC/AAPL_GROSSPROFIT_Q-APPLE-INC-AAPL-Quarterly-Gross-Profit
Quandl("SEC/AAPL_GROSSPROFIT_Q",
trim_start="2009-06-27",
trim_end="2014-03-29")
But from my understanding quandl do not have all the fundamental-details like
Bloomberg, Reuters, CapitalIQ.
There can be an issue needing to use different SEC codes to obtain comparable data on different companies so Quandl hss recently provided a harmonized set of tags which can be used for some of the more common data types. In addition to Floo0 references, you might want to check out http://www.quandl.com/help/api-for-stock-data#SEC-Harmonized-Data
I got this line of code from the maintainer of the package.There was a typo in the documentation so this is the right syntax:
Quandl("RAYMOND/MSFT_COST_OF_REVENUE_TOTAL_Q", trim_start="2009-06-27", trim_end="2014-03-29")

Using Protovis with R

As question, I have satisfied with what R and ggplot2 can do for static graph, but what about interactive graphs? How combine R and Protovis to make the graphs?
There is somethings called rwebvis but seems it is no longer active.
Any suggestion? Thanks.
Well, first you need a web server. Ooh, R has one of those now. Then you need some way of generating output on the web from R code - ooh, R has one of those too:
http://jeffreybreen.wordpress.com/2011/04/25/4-lines-of-r-to-get-you-started-using-the-rook-web-server-interface/
So you can then write R server pages that return JSON-encoded data that you can feed to Protovis - or if you want to get right up to date, to D3, which is Protovis++ and made of win.
Iplots is a fairly useful package that allows interactive graphing ( by this I mean selection linking between graphs, color linking, etc). It has some limitations and is not really made for producing plots as much as exploring data trends.
Acinonyx also was recently updated which is supposed to be an updated version of iplots, but from what I can tell it still has some work to do.
Not familiar with protovis or rwebvis.
There is a package from google called googlevis that enables some interactivity. This produces plots that are embeddable online. If you like protovis, the same author has another library called D3.
For running R on a webserver, I have been experimenting with RApache, which enables you to link your R installation to an apache server.
If the interactivity does not to be online, RStudio have a package called manipulate which may also be of interest.

How to make interactive charts together with R language

I'm helping my friend make a website. He previously used R language to generate statistical charts. Now he want to generate some dynamic chart so that when users move mouse over certain part of the chart there will be some description/complementary information pops up for them to read. What kind of technology/tools/packages I can use for this purpose?
PS: I've explored some possible ways, yet none of them fits my needs. I've tried rggobi + ggobi. They can't coz they are not for web applications. iPlot can't do it coz it generates histogram only. I've thought about asking R produces some intermediate date which I can pass to some JavaScript packages like HighCharts. Yet, apparently R is much powerful than JS. R can generates some advanced type of charts which JS just can't do.
You should use R to generate the data and then export it in a format that a javascript framework for graphs can understand.
This way you could benefit from the advanced statistical analysis provided by R and the presentation layer of javascript.
Lots of solutions exist for this problem, but i've heard lots of good things about Raphael and its chart plugin, which you may want to investigate
The playwith package offers facilities to manipulate rgl graphics. A couple of links:
http://code.google.com/p/playwith/w/list
http://www.r-bloggers.com/playing-with-the-%E2%80%98playwith%E2%80%99-package/
Look at the sendplot package or the RSVGTipsDevice package.

Resources