Is it possible to hide the point "edge" in Gadfly? - julia

In Matlab, points have a MarkerEdgeColor that can be set to "None" (or any other color).
In Julia, using Gadfly, points (Geom.point) in discrete color space have a white edge and points in continuous color space have a dark highlighted edge. I want to suppress that, so there is no "edge".

Searching on google found this issue on GitHub. But the solutions suggested there Theme(discrete_highlight_color=c->nothing) did not work for me.
Looking at the code for Geom.Point, I found that line 80 referred to a theme.highlight_width. Setting this to 0 worked for me.
using Gadfly
using DataFrames
df = DataFrame(x = randn(100), y=randn(100), c=rand(100))
plot(df, x=:x,y=:y,color=:c, Geom.point)
t = Theme(highlight_width=0)
plot(df, x=:x,y=:y,color=:c, Geom.point,t)

Related

How do I get the legend tick marks to be properly positioned using heatmap.2 in R?

I am relatively new to R and am trying to use heatmap.2(). I have found it to be a great tool, except there is one detail that is driving me crazy. The tick marks in the legend do not line up perfectly with the colors I assign in the breaks.
Below is a minimal working example. In the legend the green area goes significantly over 1, however the bottom left portion of the heatmap (value = 1.0001) is blue as I specified in the breaks. I am using RStudio Version 0.99.486 if that makes a difference. Please help!
library(gplots)
M <- matrix(c(0.5,1.0001,2.1,3.9),nrow=2)
my_palette <- c('green','blue','purple','orange')
heatmap.2(M,Colv=NULL,Rowv=FALSE,dendrogram=NULL,trace='none',density.info='none',
breaks=c(0,1,2,3,4),
col=my_palette,
key.xlab='',key.title='')

accessing shape attribute for points when making NVD3 scatterChart with nplot/rCharts

How do you set the shape attribute for points when building a scatterChart with nplot from rCharts? Point size can be set by providing a column in the input dataframe named "size" but if there's a corresponding "shape" column consisting of strings such as "square" or "cross" the resulting graph still has the default circle points. New to R and NVD3 so I apologize for my lack of vocabulary.
It appears the newest version of nvd3 no longer works the same way as the old version. See for example. The screenshot shows shapes, and the data has shape:, but only circles are rendered in the actual chart. Also, the tests do not produce anything other than circles. I glanced at the source, and I could not find where or how to set shape. If you know how to do with nvd3, I could easily translate into a rCharts example.
I don't have a reputation of 50, but I'd like to comment.
Line 18 in this NVD3 example(Novus.github) shows how it's currently done. Likewise, all you need to do with the live code(nvd3.org) is uncomment the 'size' line in the data tab.
I attempted making a column in my df named 'shape', and using n1 <- nPlot(x~y, data=df, shape='shape', type='scatterChart'); n1$chart(onlyCircles=FALSE); and a number of other combinations. I've only spent the last two days working with rCharts but have made some exciting progress. I'm giving up on this but found it curious that these two examples weren't mentioned here, so I thought I'd mention them.
I know this question is a bit "ancient" but I faced the same problem and it took me a while to find out how to change the shapes.
I followed the approach in this example for changing the size:
nvd3 scatterPlot with rCharts in R: Vary size of points?
Here my solution:
library(rCharts)
df=data.frame(x=rep(0:2,3),y=c(rep(1,3),rep(2,3),rep(3,3)),
group=c(rep("a",3),rep("b",3),rep("c",3)),shape=rep("square",9))
p <- nPlot(y~x , group = 'group',data = df, type = 'scatterChart')
#In order to make it more pleasant to look at
p$chart(xDomain=c(-0.5,2.5))
p$chart(yDomain=c(0,4))
p$chart(sizeRange = c(200,200))
#here the magic
p$chart(scatter.onlyCircles = FALSE)
p$chart(shape = '#! function(d){return d.shape} !#')
p

ggplot2 polar plot axis label location

This is just a extension for a old question
ggplot2 polar plot arrows
You will find the x axis is out of the most_out circle.
In ggplot2, I use "panel.grid.major = theme_line(colour = "black", size = 0.2, linetype=2)" to get the dashed circle, just as below:
So my question is how to make the axis label (180, 135, 90, .....) outside of the circle, because the text are merge with the circular lines.
I try to use "hjust" or "vjust" to adjust the distance between text and axis. But it does not work.
So do you have some ideas about this problem?
Thanks first!!!!
You have not provided code to reproduce the problem so this will be just a guess.
I've used whitespace, \n in particular, to move text "away" in the past. Perhaps a custom formatter might work here. Here is how you can write a custom tick mark label formatter.
If this fails, you can always hide the axis labels and paint them yourself using geom_text by adding another layer.
Hope this helps. #hadley's book on ggplot2 is very good, by the way.
I came across this question while I was trying to fix a similar issue myself. One workaround is pretty much covered in the answer to this post: Remove extra space and ring at the edge of a polar plot
You would have to adjust the limits of the x scale to match your axis labels. You would also have to create a new scale bar corresponding to the radial length of your arrows (the 0-300 scale bar on the left side of your plot), since
axis.text = element_blank
takes the scale bar away as well.

R - Scatter plots, how to plot points in differnt lines to overlapping?

I want to plot several lists of points, each list has distance (decimal) and error_no (1-8). So far I am using the following:
plot(b1$dist1, b1$e1, col="blue",type="p", pch=20, cex=.5)
points(b1$dist2, b1$e2, col="blue", pch=22)
to add them both to the same plot. (I will add legends, etc later on).
The problem I have is that points overlap, and even when changing the character using for plotting, it covers up previous points. Since I am planning on plotting a lot more than just 2 this will be a big problem.
I found some ways in:
http://www.rensenieuwenhuis.nl/r-sessions-13-overlapping-data-points/
But I would rather do something that would space the points along the y axis, one way would be to add .1, then .2, and so on, but I was wondering if there was any package to do that for me.
Cheers
M
ps: if I missed something, please let me know.
As noted in the very first point in the link you posted, jitter will slightly move all your points. If you just want to move the points on the y-axis:
plot(b1$dist1, b1$e1, col="blue",type="p", pch=20, cex=.5)
points(b1$dist2, jitter(b1$e2), col="blue", pch=22)
Depends a lot on what information you wish to impart to the reader of your chart. A common solution is to use the transparency quality of R's color specification. Instead of calling a color "blue" for example, set the color to #0000FF44 (Apologies if I just set it to red or green) The final two bytes define the transparency, from 00 to FF, so overlapping data points will appear darker than standalone points.
Look at the spread.labs function in the TeachingDemos package, particularly the example. It may be that you can use that function to create your plot (the examples deal with labels, but could just as easily be applied to the points themselves). The key is that you will need to find the new locations based on the combined data, then plot. If the function as is does not do what you want, you could still look at the code and use the ideas to spread out your points.
Another approach would be to restructure your data and use the ggplot2 package with "dodging". Other approaches rather than using points several times would be the matplot function, using the col argument to plot with a vector, or lattice or ggplot2 plots. You will probably need to restructure the data for any of these.

R: how to change lattice (levelplot) color theme?

The default theme on my installation is something which maps the values to pink and cyan. How to change it for example to a gray scale theme?
You can use
library(lattice)
lattice.options(default.theme = standard.theme(color = FALSE))
which turns on black-and-white suitable for printing. I've also played with things like
sb <- trellis.par.get("strip.background")
sb[["col"]][1] <- "lightgray"
trellis.par.set("strip.background", sb)
which changes just the header background.
And I thought people only asked ggplot2 questions here :) Nice to see some lattice for a change.
Thanks for the answers guys! It also helped me to find more information on the subject. I learned that I can control the scales of gray using for example the following:
levelplot(my_var, col.regions = gray(0:100/100))
which gives me 100 shades of gray from black (0) to white (1).
I'm using the function to plot gray scale images (photos) which I've pre-processed to a double matrix. I don't know if it's the best possible approach, but so far it works and I believe it gives me more options for graphing than the basic displaying options in the EBImage and rimage libraries. I don't know how I'd alter the palette to match displaying color images, but I'm glad I didn't have to do that so far...
There are many ways to accomplish your request. The simplest is:
trellis.device(color = FALSE)
another is
ltheme <- canonical.theme(color = FALSE) ## in-built B&W theme
ltheme$strip.background$col <- "transparent" ## change strip bg
lattice.options(default.theme = ltheme) ## set as default
See this mail archive item: Re: [R] specify lattice black-and-white theme for more info.
You may also want to consider using panel.levelplot.raster, as it reduces the figure size sizably, as I recently found out. Combining this tip with changing trellis settings in general, here are a following examples:
trellis.par.set(regions=list(col=topo.colors(100)))
levelplot(volcano, panel = panel.levelplot.raster)
levelplot(volcano, panel = panel.levelplot.raster,
par.settings=list(regions=list(col=topo.colors(100))))
The second method is deceptive because the trellis settings are in fact being changed globally. I didn't know about the col.regions argument though - that's pretty nice as it seems to change the color theme locally.
The only one that worked for me is:
>trellis.par.set(canonical.theme(color = FALSE))

Resources