Overlay of multiple time series in Quantmod in R - r

I want to create a chart using chartSeries with two or more time series on the SAME chart (overlaying each other). Bing/search doc have gotten me nowhere. Seems like should be fairly easy, I tried addTA, but didn't work. I tried the following code.
chartSeries(c(PSEC, ARCC), type = "line")
That resulted into this: (nevermind the fonts, the hell is the green blob?)

The green blob is what you asked R to plot. c(PSEC, ARCC) is the same as rbind(PSEC, ARCC), which creates a single OHLCVA object with two observations per index value (one for PSEC, one for ARCC). You said you tried addTA, but it "didn't work". Saying something "doesn't work" does not help people help you, especially when you don't even show the code that "doesn't work".
Here's a chartSeries call that uses addTA, and a corresponding chart_Series version. Note that chart_Series automatically handles the y-axis range for you.
> chartSeries(Cl(PSEC), TA="addTA(Cl(ARCC), on=1)")
> chart_Series(Cl(PSEC), TA="add_TA(Cl(ARCC), on=1)")

Your data, if it is not daily, could easily look like a green blob.
For example, if that's minute-by-minute prices, I'd expect it to look like this upon visual inspection.

Related

How to Change X-Axis Label in ChromoMap?

I am new to R and I have been using chromoMap library in R to visualize annotation plots and visualizing the feature-associated data. It's a great library and produces great charts. However, I was not able to find any option for changing the x-axis label from length (bp) to anything else. Because of this, I am not able to use any of the produced charts. It sounds like a small issue, but it totally affects the usability of this great package. I followed this tutorial link and produced the below chart. In my chart and all the samples, the x-axis label is fixed and this is my problem and I am looking for a way to just change it.
library(chromoMap)
chr_file_1 = "chr_file_without_centromere.txt"
anno_file_1 = "annotation_pos.txt"
chromoMap(chr_file_1,anno_file_1)
I am wondering if anybody has the same experience ?? This package produces output as a htmlwidget object and therefore I could not change the x-axis lable. Is there any way to modify a htmlwidget object? or Any way to change this bp to something else??

Issues with combining different (continuous and ordinal) plot types into one plot

I am preparing a figure for a paper presenting data for 2 different experiments in one plot. For that reason I don't need a legend for every plot, so I try to combine them with ggdraw from cowplot.
My code
should generate a reproducible example
and gives this output:
It seems like the two figures get the same slot (A) and the legend gets slot (B). Typically, I would probably use facet wrap to plot them together (which should also guarantee that the scaling/legend is consistent across the two plots.), but that will probably not work in this case, as I am trying to add an additional figure type to C and D.
The problem is that this figure type is ordinal so I have used a somewhat “hacky” approach to plot it, giving me this figure looking essentially as I want it to:
I so far have not been able to extract to another element that ggdraw can use.
Ideally the final plot should roughly look like this (of course with different labels):
How would you go about plotting these different types together?
Thank you for taking time to read my question and I hope that you can help me. I now it is quite a mouth full, but I was not sure how I meaningfully could reduce it to smaller chunks.

How to combine two data sets into one and plotting one graph with both data sets in R Studio

Currently I have combined the Apple stock market and the Samsung stock market from 2014- 2018. I have combined the Date,Open,High, low and Close using cbind and changed the names so it says Apple/ Samsung.
My problem is with the graph, Now my dataset is combined in columns so I feel like this might be part of the problem, but none the less I would prefer to keep it like that. I would love a graph that would have both of the open figures on it over the years.
If I just use plot(Total$OpenApple, Total$OpenSam) the plot is a huge block compared to the line graph I would like.
Thanks.
Without any example data its difficult to understand your problem fully. However, I would try using the ggplot2 package and dplyr package. Then you can change your data so that OpenApple and OpenSam are both part of the same column, and then use a function from ggplot2 to change the colors of your lines based on what group they are a part of.

SVGAnnotation to create tool tips for each value in R heatmaps

I'd like to create a heat map in R that I want to use on a website. I stumbled upon the SVGAnnotation package which seems to be very nice to process SVG graphics in R to make them more interactive. First, I was planning to add tool tips for each cell in the heatmap - if the user hovers over the cell, the value of this cell should pop up. However, I am fighting with SVGAnnotation for more than 3 hours now, reading and trying things, and I can't get it to work.
I would appreciate any help on the SVGAnnotation tool tip function. But I would also very much appreciate alternatives to SVGAnnotation to add some activity to my R SVG heatmap.
So, what I have got so far looks like this:
library(SVGAnnotation)
data(mtcars)
cars <- as.matrix(mtcars)
map <- svgPlot(heatmap(cars))
addToolTips(map, ...) # problem
saveXML(map, "cars.svg")
My problem is the addToolTips function itself, I guess. Intuitively, I would simply insert the data matrix, i.e., cars, but this does not work and R gets stuck (it's calculating, but doesn't return anything, I waited 50 minutes)
EDIT:
After some more online research, I found a good example of what I want to achieve: http://online.wsj.com/article/SB125993225142676615.html#articleTabs=interactive
This heat map looks really great, and the interactive features (tool tips) work very well. I am wondering how they did that. To me, it looks like the graphic was done in R using the ggplot package.
I wrote a command line tool that can do exactly that if you are still interested to add tool tips to your heat map. It runs in Windows/Linux/MacOS terminals. All you need as input is the heat map as svg file and the data table/matrix that you used as input to create your heat map as csv or other text file.

Plotting large numbers with R, but not all numbers are being shown

I am trying to render 739455 data point on a graph using R, but on the x-axis I can not view all those numbers, is there a way I can do that?
I am new to R.
Thank you
As others suggested, try hist, hexbin, plot(density(node)), as these are standard methods for dealing with more points than pixels. (I like to set hist with the parameter breaks = "FD" - it tends to have better breakpoints than the default setting.)
Where you may find some joy is in using the iplots package, an interactive plotting package. The corresponding commands include ihist, iplot, and more. As you have a Mac, the more recent Acinonyx package may be even more fun. You can zoom in and out quite easily. I recommend starting with the iplots package as it has more documentation and a nice site.
If you have a data frame with several variables, not just node, then being able to link the different plots such that brushing points in one plot highlights them in another will make the whole process more stimulating and efficient.
That's not to say that you should ignore hexbin and the other ideas - those are still very useful. Be sure to check out the options for hexbin, e.g. ?hexbin.

Resources