Stacked bar charts use a hue-based colour scale by default, in order to distinguish the different sections of bar. Since the factor levels corresponding to my stacks are ordered, I would like to use a gradient scale.
Here's some made-up questionnaire data
dfr <- data.frame(
question = c("Do you like R?", "How about Stack Overflow?")...
When trying to read a csv file in StatET/Eclipse (OS X 10.6, Eclipse 3.6) using the following command:
read.csv(file.choose(),header=T)
I get the response:
Error in file.choose() : file choice cancelled
The command works as expected in 'R' itself and reading a named csv file works in StatET. What am I doing wrong?
Thanks in adva...
Is it possible to plot a matrix of scatter plots with ggplot2, using ggplot's nice features like mapping additional factors to color, shape etc. and adding smoother?
I am thinking about something similar to pairs().
...
Dear Coding Experts
I have a project in which i need to be able to calculate different voting power indexes in R. As a first attempt at this I wrote a small function to calculate the banzhaf index. It takes two arguments, a dataframe that has two columns which must be labelled member and vote, and how many votes are needed for a majorit...
Yesterday I worked up an example of the difference between Ordinary Least Squares (OLS) vs. Principal Components Analysis (PCA). For that illustration I wanted to show the errors minimized by OLS and PCA so I plotted the actuals, the predicted line and then I manually (with GIMP) drew in a drop line to illustrate a couple of the error te...
In R, for example
> foo <- list(a=1,b=2,c=3)
if I type foo, get
$a
[1] 1
$b
[1] 2
$c
[1] 3
How can I look through foo to get a list of 'keys' only, in this case, (a, b, c)?
Thanks all
...
I'm having trouble passing a POSIXct stored in a variable as the xmin/xmax for geom_rect. I've tried to construct a free-standing example without trivializing what I'm trying to do...
The idea is to take a ggplot2 plot object, whose x is a POSIXt, and "zoom in" on a particular range in time. The zoom is in the top 80% and the entire ser...
Hi,
I try am trying to use the "to.minutes3" function in the xts package to segment my data.
This function does correctly put the time column into the desired intervals. But data columns becomes "open" , "close", "high" and "low". Is there are way tell the function to average the data points that fall into the same interval?
Thanks,
...
There are 25 symbols defined by 'pch' paramter in the points function.
How can I draw more than these 25 symbols
Thanks
...
Hi All,
I am somewhat new to R and I have run into a point where I need some help. I figure the reshape package can accomplish what I need to do.
Here is the structure of the original data frame:
> str(bruins)
'data.frame': 10 obs. of 6 variables:
$ gameid : Factor w/ 1 level "20090049": 1 1 1 1 1 1 1 1 1 1
$ team : chr "NYI...
Dear all,
Due to hetereoscedasticity I'm doing bootstrapped linear regression (appeals more to me than robust regression). I'd like to create a plot along the lines of what I've done in the script here. However the fill=int is not right since int should (I believe) be calculated using a bivariate normal distribution.
-Any idea how I c...
I think I'm getting a scoping error when using transformBy(), part of the doBy package for R. Here is a simple example of the problem:
> library(doBy)
>
> test.data = data.frame(
+ herp = c(1,2,3,4,5),
+ derp = c(2,3,1,3,5)
+ )
>
> transformData = function(data){
+
+ five = 5
+
+ transformBy(
+ ~ herp,
+ data=data,
+ sum=he...
I have a data.frame, that is sorted from highest to lowest. For example:
x <- structure(list(variable = structure(c(10L, 6L, 3L, 4L, 2L, 8L,
9L, 5L, 1L, 7L), .Label = c("a", "b", "c", "d", "e", "f", "g",
"h", "i", "j"), class = c("ordered", "factor")), value = c(0.990683229813665,
0.975155279503106, 0.928571428571429, 0.807453416149...
The two posts below are great examples of different approaches of extracting data from websites and parsing it into R.
Scraping html tables into R data frames using the XML package
How can I use R (Rcurl/XML packages ?!) to scrape this webpage
I am very new to programming, and am just starting out with R, so I am hoping this questio...
Dear all,
I'm doing coarsened exact matching on an imputed dataset. To validate I do bootstrapping of the results from cem. However I'm unable to get boot.ci output to work. I get the error msg
Error in bca.ci(boot.out, conf, index[1L], L = L, t = t.o, t0 = t0.o, :
estimated adjustment 'a' is NA
The object is there but for some r...
I have a function, as follows:
f.factor <- function(x) {
print(length(unique(x)))
z <- 1
for (i in 1:length(unique(x))) {
z[i] <- readline(":")
}
x <- factor(x, labels=c(z))
return(x)
}
Essentially, it allows me to copy/paste/type or just simply write into my script the factors for a particular variable without havi...
I am just starting out with R, and beginning to start producing charts. I am aware that there are at least three different plotting packages, the standard one, ggplot2 and lattice.
Are these packages complementary, or do they cover much the same ground? If they are complementary, when do I use each? If they cover the same ground, whi...
Hello
How can I substitute NA values by zero in a R zoo series?
I've been reading about na.locf and na.omit but I think none of them do what I need.
thanks.
...
I tried to do something like this:
x <- data.frame(1:20)
attach(x)
assign("x2",1:20,pos="x")
However, x$x2 gives me NULL.
With x2 I get what I want but it is not part of the data.frame.
Attaching x2 to x manually would work in this simple case but not in the more complex one I need. I try to assign in a loop where I loop over...
Hi
I have a large dataset with repeat assessment across subjects. How do I go from:
subj, assessment, test1, test2
A, 1, 10, 20
A, 2, 12, 13
A, 3, 11, 12
B, 1, 14, 14
B, 2, 13, 12
To:
subj, test1_1, test1_2, test1_3
A, 10, 12, 11
B, 14, 13
Thanks,
Jon
...