Hi, i'd like to plot some data that I have with the value on the x axis and freq on the y axis. So, I need to calculate the freq a value is seen within my data vector for example, say i have a vector of data data=c(1,1,1,4,5,5,6) I want values<-c(1,4,5,6) freq<-c(3,1,2,1) in order to enable me to plot this. Sorry, i'm new to R. What is standard procedure here for plotting the data vector? cheers Rich
On Thu, 2008-02-14 at 14:35 +0000, rich at thevillas.eclipse.co.uk wrote:> Hi, > > i'd like to plot some data that I have with the value on the x axis and freq > on the y axis. > > So, I need to calculate the freq a value is seen within my data vector > > for example, say i have a vector of data > > data=c(1,1,1,4,5,5,6)Don't call your data 'data' ;-) install.packages("fortunes") library(fortunes) fortune("dog")> > I want > > values<-c(1,4,5,6) > > freq<-c(3,1,2,1)use ?unique and ?table my.dat <- c(1,1,1,4,5,5,6) values <- unique(my.dat) values tab <- table(dat) tab freq <- as.numeric(tab) freq plot(tab) # for one way of plotting what you want plot(freq ~ values) # for another HTH G> > in order to enable me to plot this. Sorry, i'm new to R. What is standard > procedure here for plotting the data vector? > > cheers > > Rich > > > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Hi rich, >data <- c(1,1,1,4,5,5,6) >table(data) data 1 4 5 6 3 1 2 1 hope it helps josephine rich at thevillas.eclipse.co.uk wrote:> Hi, > > i'd like to plot some data that I have with the value on the x axis and freq > on the y axis. > > So, I need to calculate the freq a value is seen within my data vector > > for example, say i have a vector of data > > data=c(1,1,1,4,5,5,6) > > I want > > values<-c(1,4,5,6) > > freq<-c(3,1,2,1) > > in order to enable me to plot this. Sorry, i'm new to R. What is standard > procedure here for plotting the data vector? > > cheers > > Rich > > > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Here are a couple of ways depending on what you want. data1=c(1,1,1,4,5,5,6) plot(table(data1)) --------------------------------------- plotvec <- as.vector(aa) nns <- names(aa) plot(plotvec, xaxt="n") mtext(nns, at=1:4, side=1) --------------------------------------- --- "rich at thevillas.eclipse.co.uk" <rich at thevillas.eclipse.co.uk> wrote:> > Hi, > > i'd like to plot some data that I have with the > value on the x axis and freq > on the y axis. > > So, I need to calculate the freq a value is seen > within my data vector > > for example, say i have a vector of data > > data=c(1,1,1,4,5,5,6) > > I want > > values<-c(1,4,5,6) > > freq<-c(3,1,2,1) > > in order to enable me to plot this. Sorry, i'm > new to R. What is standard > procedure here for plotting the data vector? > > cheers > > Rich > > > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code. >[[elided trailing spam]]
Try this: values <- c(1,1,1,4,5,5,6) with(rle(values), plot(values, lengths)) But I think that you can use barplot: barplot(table(values)) On 14/02/2008, rich at thevillas.eclipse.co.uk <rich at thevillas.eclipse.co.uk> wrote:> > Hi, > > i'd like to plot some data that I have with the value on the x axis and freq > on the y axis. > > So, I need to calculate the freq a value is seen within my data vector > > for example, say i have a vector of data > > data=c(1,1,1,4,5,5,6) > > I want > > values<-c(1,4,5,6) > > freq<-c(3,1,2,1) > > in order to enable me to plot this. Sorry, i'm new to R. What is standard > procedure here for plotting the data vector? > > cheers > > Rich > > > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
rich at thevillas.eclipse.co.uk wrote:> Hi, > > i'd like to plot some data that I have with the value on the x axis and freq > on the y axis. > > So, I need to calculate the freq a value is seen within my data vector > > for example, say i have a vector of data > > data=c(1,1,1,4,5,5,6) > > I want > > values<-c(1,4,5,6) > > freq<-c(3,1,2,1) > > in order to enable me to plot this. Sorry, i'm new to R. What is standard > procedure here for plotting the data vector? > >Here's one way: rich.dat<-c(1,1,1,4,5,5,6) library(plotrix) library(prettyR) barp(freq(rich.dat)[[1]],names.arg=unique(rich.dat)) Jim