Hi Eliza,
Try this:
BAS1<-
structure(c(3, 4, 2, 3, 3, 4, 3, 3, 3, 3, 2, 3, 3, 4, 3, 2, 2,
3, 2, 3, 3, 3, 4, 5, 3, 4, 3, 4, 4, 3, 4, 4, 3, 3, 3, 4, 3, 3,
3, 4, 3, 3, 4, 5, 4, 4, 4, 3, 4, 3, 3, 3, 3, 4, 4, 5, 4, 3, 4,
4, 2, 3, 3, 3, 2, 4, 4, 3, 3, 4, 3, 3, 3, 3, 4, 4, 3, 3, 2, 3,
3, 3, 3, 2, 5, 2, 4, 3, 2, 3, 4, 3, 4, 4, 3, 4, 4, 3, 3, 3, 2,
3, 4, 3, 4, 4, 3, 3, 3, 3, 5, 3, 3, 5, 3, 4, 2, 3, 3, 3, 3, 3,
4, 3, 3.93, 3.509, 2.464, 2.72, 2.304, 3.517, 3.517, 6.675, 6.597,
2.715, 2.849, 2.618, 3.126, 2.715, 3.931, 3.709, 3.931, 4.145,
6.585, 3.907, 3.132, 2.568, 3.883, 2.447, 3.517, 7.098, 3.027,
3.003, 7.098, 2.374, 2.065, 2.95, 3.559, 5.102, 3.907, 3.204,
3.207, 2.791, 2.116, 3.003, 3.003, 3.003, 6.049, 3.52, 2.241,
3.883, 4.145, 3.334, 3.151, 6.269, 4.04, 3.883, 2.27, 3.304,
2.464, 4.111, 2.728, 3.93, 3.911, 2.447, 3.202, 2.375, 2.442,
2.442, 2.592, 2.13, 3.122, 5.657, 6.076, 4.186, 2.115, 2.623,
6.076, 2.467, 2.623, 2.629, 2.517, 2.623, 2.517, 4.32, 4.045,
6.597, 4.079, 3.817, 3.521, 2.564, 3.071, 2.447, 3.334, 2.442,
2.248, 3.094, 4.045, 4.045, 2.252, 2.971, 3.727, 2.184, 2.783,
2.849, 3.529, 2.484, 2.184, 2.313, 2.512, 3.4, 4.096, 3.572,
2.663, 3.405, 5.102, 3.267, 2.987, 2.123, 3.47, 2.512, 2.783,
6.597, 6.435, 4.921, 3.351, 2.07, 2.07, 2.442), .Dim = c(124L,
2L))
library(plotrix)
x11(width=12,height=5)
barp(BAS1[,1],main="Plot of BAS1",ylim=c(0,10),col="green")
plotlim<-par("usr")
rect(seq(0.6,123.6,1),plotlim[4]-BAS1[,2],
seq(1.4,124.4,1),plotlim[4],col="red")
This clearly needs refinement, but it's a start.
Jim
On Mon, Oct 18, 2021 at 12:15 PM Eliza Botto <eliza_botto at outlook.com>
wrote:>
> Dear useRs,
>
> Sorry for a very basic question. I have the following data set containing 2
columns.
>
> > dput(BAS1)
>
> structure(c(3, 4, 2, 3, 3, 4, 3, 3, 3, 3, 2, 3, 3, 4, 3, 2, 2,
> 3, 2, 3, 3, 3, 4, 5, 3, 4, 3, 4, 4, 3, 4, 4, 3, 3, 3, 4, 3, 3,
> 3, 4, 3, 3, 4, 5, 4, 4, 4, 3, 4, 3, 3, 3, 3, 4, 4, 5, 4, 3, 4,
> 4, 2, 3, 3, 3, 2, 4, 4, 3, 3, 4, 3, 3, 3, 3, 4, 4, 3, 3, 2, 3,
> 3, 3, 3, 2, 5, 2, 4, 3, 2, 3, 4, 3, 4, 4, 3, 4, 4, 3, 3, 3, 2,
> 3, 4, 3, 4, 4, 3, 3, 3, 3, 5, 3, 3, 5, 3, 4, 2, 3, 3, 3, 3, 3,
> 4, 3, 3.93, 3.509, 2.464, 2.72, 2.304, 3.517, 3.517, 6.675, 6.597,
> 2.715, 2.849, 2.618, 3.126, 2.715, 3.931, 3.709, 3.931, 4.145,
> 6.585, 3.907, 3.132, 2.568, 3.883, 2.447, 3.517, 7.098, 3.027,
> 3.003, 7.098, 2.374, 2.065, 2.95, 3.559, 5.102, 3.907, 3.204,
> 3.207, 2.791, 2.116, 3.003, 3.003, 3.003, 6.049, 3.52, 2.241,
> 3.883, 4.145, 3.334, 3.151, 6.269, 4.04, 3.883, 2.27, 3.304,
> 2.464, 4.111, 2.728, 3.93, 3.911, 2.447, 3.202, 2.375, 2.442,
> 2.442, 2.592, 2.13, 3.122, 5.657, 6.076, 4.186, 2.115, 2.623,
> 6.076, 2.467, 2.623, 2.629, 2.517, 2.623, 2.517, 4.32, 4.045,
> 6.597, 4.079, 3.817, 3.521, 2.564, 3.071, 2.447, 3.334, 2.442,
> 2.248, 3.094, 4.045, 4.045, 2.252, 2.971, 3.727, 2.184, 2.783,
> 2.849, 3.529, 2.484, 2.184, 2.313, 2.512, 3.4, 4.096, 3.572,
> 2.663, 3.405, 5.102, 3.267, 2.987, 2.123, 3.47, 2.512, 2.783,
> 6.597, 6.435, 4.921, 3.351, 2.07, 2.07, 2.442), .Dim = c(124L,
> 2L))
>
> I want to draw bar chart in such a way that column 1 is drawn on primary y
axis with bars rising, while the column 2 is draw on a secondary y axis with
bar-plots falling down from the top exactly on the top of rising bars. For
example, the plot of 1st row of column one should be overshadowed by the bar of
1st row of column 2. Additionally, I want all the bars to be red while 3rd and
102nd bar of rising and falling bars to be coloured green.
>
> I hope I am clear ?. Thank-you very much in advance.
>
>
>
> regards,
>
> Eliza
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
Admire Tarisirayi Chirume
2021-Oct-18 11:26 UTC
[R] creating a new variable and merging it on the dataframe
Good day colleagues. Below is a csv file attached which i am using in my
analysis.
hh.id
hd17.perm
hd17employ
health.exp
total.food.exp
total.nfood.exp
1
2
yes
1654
23654
23655
2
2
yes
2564
265897
65984
3
6
no
2547
123311
52416
4
8
no
5698
13648
12544
5
6
no
1254
36549
12365
6
8
yes
1236
236541
26522
7
8
no
4521
13264
23698
So I created a df using the above csv file as follows
wbpractice <- read.csv("world_practice.csv")
Now, I wanted to create a new variable called gap and scripted and executed
the following command :
wbpractice %>%
mutate(gap = total.food.exp-total.nfood.exp) #gen a variable
By recalling wbpractice, I could not see the new variable created. Running
the command;
names(wbpractice)
shows the old variables only. Any help on how to append the newly created
variable on my data?
Alternative email: addtarris at icloud.com/TChirume at rbz.co.zw
Skype: admirechirume
Call: +263773369884
whatsapp: +818099861504
>
[[alternative HTML version deleted]]
Thanks everyone. It helped.
________________________________
From: Jim Lemon <drjimlemon at gmail.com>
Sent: Monday 18 October 2021 04:01
To: Eliza Botto <eliza_botto at outlook.com>; r-help mailing list
<r-help at r-project.org>
Subject: Re: [R] Rising and falling bar-plots simultaneously
Hi Eliza,
Try this:
BAS1<-
structure(c(3, 4, 2, 3, 3, 4, 3, 3, 3, 3, 2, 3, 3, 4, 3, 2, 2,
3, 2, 3, 3, 3, 4, 5, 3, 4, 3, 4, 4, 3, 4, 4, 3, 3, 3, 4, 3, 3,
3, 4, 3, 3, 4, 5, 4, 4, 4, 3, 4, 3, 3, 3, 3, 4, 4, 5, 4, 3, 4,
4, 2, 3, 3, 3, 2, 4, 4, 3, 3, 4, 3, 3, 3, 3, 4, 4, 3, 3, 2, 3,
3, 3, 3, 2, 5, 2, 4, 3, 2, 3, 4, 3, 4, 4, 3, 4, 4, 3, 3, 3, 2,
3, 4, 3, 4, 4, 3, 3, 3, 3, 5, 3, 3, 5, 3, 4, 2, 3, 3, 3, 3, 3,
4, 3, 3.93, 3.509, 2.464, 2.72, 2.304, 3.517, 3.517, 6.675, 6.597,
2.715, 2.849, 2.618, 3.126, 2.715, 3.931, 3.709, 3.931, 4.145,
6.585, 3.907, 3.132, 2.568, 3.883, 2.447, 3.517, 7.098, 3.027,
3.003, 7.098, 2.374, 2.065, 2.95, 3.559, 5.102, 3.907, 3.204,
3.207, 2.791, 2.116, 3.003, 3.003, 3.003, 6.049, 3.52, 2.241,
3.883, 4.145, 3.334, 3.151, 6.269, 4.04, 3.883, 2.27, 3.304,
2.464, 4.111, 2.728, 3.93, 3.911, 2.447, 3.202, 2.375, 2.442,
2.442, 2.592, 2.13, 3.122, 5.657, 6.076, 4.186, 2.115, 2.623,
6.076, 2.467, 2.623, 2.629, 2.517, 2.623, 2.517, 4.32, 4.045,
6.597, 4.079, 3.817, 3.521, 2.564, 3.071, 2.447, 3.334, 2.442,
2.248, 3.094, 4.045, 4.045, 2.252, 2.971, 3.727, 2.184, 2.783,
2.849, 3.529, 2.484, 2.184, 2.313, 2.512, 3.4, 4.096, 3.572,
2.663, 3.405, 5.102, 3.267, 2.987, 2.123, 3.47, 2.512, 2.783,
6.597, 6.435, 4.921, 3.351, 2.07, 2.07, 2.442), .Dim = c(124L,
2L))
library(plotrix)
x11(width=12,height=5)
barp(BAS1[,1],main="Plot of BAS1",ylim=c(0,10),col="green")
plotlim<-par("usr")
rect(seq(0.6,123.6,1),plotlim[4]-BAS1[,2],
seq(1.4,124.4,1),plotlim[4],col="red")
This clearly needs refinement, but it's a start.
Jim
On Mon, Oct 18, 2021 at 12:15 PM Eliza Botto <eliza_botto at outlook.com>
wrote:>
> Dear useRs,
>
> Sorry for a very basic question. I have the following data set containing 2
columns.
>
> > dput(BAS1)
>
> structure(c(3, 4, 2, 3, 3, 4, 3, 3, 3, 3, 2, 3, 3, 4, 3, 2, 2,
> 3, 2, 3, 3, 3, 4, 5, 3, 4, 3, 4, 4, 3, 4, 4, 3, 3, 3, 4, 3, 3,
> 3, 4, 3, 3, 4, 5, 4, 4, 4, 3, 4, 3, 3, 3, 3, 4, 4, 5, 4, 3, 4,
> 4, 2, 3, 3, 3, 2, 4, 4, 3, 3, 4, 3, 3, 3, 3, 4, 4, 3, 3, 2, 3,
> 3, 3, 3, 2, 5, 2, 4, 3, 2, 3, 4, 3, 4, 4, 3, 4, 4, 3, 3, 3, 2,
> 3, 4, 3, 4, 4, 3, 3, 3, 3, 5, 3, 3, 5, 3, 4, 2, 3, 3, 3, 3, 3,
> 4, 3, 3.93, 3.509, 2.464, 2.72, 2.304, 3.517, 3.517, 6.675, 6.597,
> 2.715, 2.849, 2.618, 3.126, 2.715, 3.931, 3.709, 3.931, 4.145,
> 6.585, 3.907, 3.132, 2.568, 3.883, 2.447, 3.517, 7.098, 3.027,
> 3.003, 7.098, 2.374, 2.065, 2.95, 3.559, 5.102, 3.907, 3.204,
> 3.207, 2.791, 2.116, 3.003, 3.003, 3.003, 6.049, 3.52, 2.241,
> 3.883, 4.145, 3.334, 3.151, 6.269, 4.04, 3.883, 2.27, 3.304,
> 2.464, 4.111, 2.728, 3.93, 3.911, 2.447, 3.202, 2.375, 2.442,
> 2.442, 2.592, 2.13, 3.122, 5.657, 6.076, 4.186, 2.115, 2.623,
> 6.076, 2.467, 2.623, 2.629, 2.517, 2.623, 2.517, 4.32, 4.045,
> 6.597, 4.079, 3.817, 3.521, 2.564, 3.071, 2.447, 3.334, 2.442,
> 2.248, 3.094, 4.045, 4.045, 2.252, 2.971, 3.727, 2.184, 2.783,
> 2.849, 3.529, 2.484, 2.184, 2.313, 2.512, 3.4, 4.096, 3.572,
> 2.663, 3.405, 5.102, 3.267, 2.987, 2.123, 3.47, 2.512, 2.783,
> 6.597, 6.435, 4.921, 3.351, 2.07, 2.07, 2.442), .Dim = c(124L,
> 2L))
>
> I want to draw bar chart in such a way that column 1 is drawn on primary y
axis with bars rising, while the column 2 is draw on a secondary y axis with
bar-plots falling down from the top exactly on the top of rising bars. For
example, the plot of 1st row of column one should be overshadowed by the bar of
1st row of column 2. Additionally, I want all the bars to be red while 3rd and
102nd bar of rising and falling bars to be coloured green.
>
> I hope I am clear ?. Thank-you very much in advance.
>
>
>
> regards,
>
> Eliza
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
[[alternative HTML version deleted]]