Skip to navigation

ggplot2 error “invalid argument to unary operator”

August 8th, 2011

I had a longish ggplot command and kept getting the error:

invalid argument to unary operator

It happened when I was specifying custom labels with scale_y_continuous but it turns out this was irrelevant and it hinged on a line break. It turnsout (at least when stepping through the code with ESS in Emacs using C-c C-c, bound to ess-eval-function-or-paragraph-and-step, you need to have the + of tying different ggplot bits together on the end of the preceding line.

This won’t work:

ggplot(longdata, aes(x=x, y = y))
+ geom_jitter(alpha = 0.6)

This will:

ggplot(longdata, aes(x=x, y = y)) +
geom_jitter(alpha = 0.6)

(Or, put it all on one line).


December 14th, 2010

I came across flexSURVEY, which looks similar in idea to my Template 2.0 for web experiments, except flexSURVEY uses PHP (Template 2.0 is pure JavaScript up to the point of data submission at the end).

I haven’t tried it, but it looks like it could be a nice way to do some speedy PHP-based questionnaires.

Use sed to remove the first column in a comma separated file (csv)

August 2nd, 2010

Here’s how:

sed -i 's/[^,]*,//' file.csv

Note the [^,]* bit, which matches everything that is not a comma. Don’t use .*, because this will greedily match commas, too. (Usually, cut is useful for these sort of things, but cut cannot readily replace the file in place.)

How to get Emacs key bindings in Ubuntu

February 16th, 2010

To get the Emacs key bindings (especially, Ctrl-a to go to beginning of line, Ctrl-e to end of line) systemwide, e.g. in Firefox, you use:


and change the setting desktop → gnome → interface → gtk_key_theme from “Default” to “Emacs”.

How not to ask a question on R-help

February 12th, 2010

One great way to get help with R is by asking a question on the r-help mailing list. More often than not I have actually figured out the answer simply by typing up the question, because that made me think more clearly about what the problem really was. The people on the list are exceedingly helpful. Not all of the posters are. I’ll now start collecting some fun examples of threads which might be called “How not to ask a quesiton on R-help”. Here is the first one. Nice quote from Greg Snow:

If you show us your data/code/output as has been requested, then we may be able to tell which it is. Without that information you are expecting either R or the members of the list to read your mind. I keep making notes to my future self to use the timetravel package (not written yet, that’s why I need my future self to use it) to send a copy of the esp package (also not written yet) back in time to me so I can use it for situations like this. But so far that has not worked (maybe my future self is even more lazy than my present self, or my near future self does something to offend my far future self enough that he is unwilling to do this small favor for my current past self, darn, either way means I should probably do better on the diet/exercise).