Re: [R] Plotting factors in graph panel

2023-07-11 Thread Anupam Tyagi
Wonderful! This is great news. Thanks, Deepayan.

On Wed, 12 Jul 2023 at 09:21, Deepayan Sarkar 
wrote:

>
>
> On Wed, 12 Jul 2023 at 08:57, Anupam Tyagi  wrote:
>
>> Thanks.
>> I made a graph in Stata that is close to what I want in R. Stata graph is
>> attached. The main differences between Stata and R graphs that I was able
>> to make, with ggplot or lattice, is that I have been able to scale y-axis
>> of each sub-graph independently in Stata, but not in R. Also, x-axis
>> labels
>> are also complete in Stata but not in R. Is there a way to do this in R
>> via
>> base-R, ggplot or lattice?
>
>
> Yes, of course. For lattice, add the argument
>
> scales = list(y = "free")
>
> For ggplot2, change
>
> facet_wrap(~Measure)
>
> to
>
> facet_wrap(~Measure, scale = "free")
>
> -Deepayan
>
> I had initially thought that these types of
>> panel graphs are common and should be easy to do, but that is not how this
>> is turning out to be. Any help is welcome.
>>
>
>> On Fri, 7 Jul 2023 at 17:57, PIKAL Petr  wrote:
>>
>> > Hallo Anupam
>> >
>> > With
>> >
>> > ggplot change axis label size into Google
>> >
>> > the first answer I got was
>> >
>> > axis.text theme
>> >
>> > r - Change size of axes title and labels in ggplot2 - Stack Overflow
>> > <
>> https://stackoverflow.com/questions/14942681/change-size-of-axes-title-and-labels-in-ggplot2
>> >
>> >
>> >
>> >
>> > so
>> >
>> >
>> >
>> > ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) +
>> geom_point()
>> > +
>> >   geom_line() + facet_wrap(~Measure) +
>> > theme(axis.text=element_text(size=5))
>> >
>> >
>> >
>> > Should do the trick.
>> >
>> >
>> >
>> > S pozdravem | Best Regards
>> >
>> >
>> > *RNDr. Petr PIKAL*Vedoucí Výzkumu a vývoje | Research Manager
>> >
>> >
>> > *PRECHEZA a.s.*nábř. Dr. Edvarda Beneše 1170/24 | 750 02 Přerov | Czech
>> > Republic
>> > Tel: +420 581 252 256 | GSM: +420 724 008 364
>> > petr.pi...@precheza.cz | *www.precheza.cz <https://www.precheza.cz/>*
>> >
>> > *Osobní údaje: *Informace o zpracování a ochraně osobních údajů
>> > obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: *
>> https://www.precheza.cz/zasady-ochrany-osobnich-udaju/
>> > <https://www.precheza.cz/zasady-ochrany-osobnich-udaju/>* | Information
>> > about processing and protection of business partner’s personal data are
>> > available on website: *
>> https://www.precheza.cz/en/personal-data-protection-principles/
>> > <https://www.precheza.cz/en/personal-data-protection-principles/>*
>> >
>> > *Důvěrnost: *Tento e-mail a jakékoliv k němu připojené dokumenty jsou
>> > důvěrné a podléhají tomuto právně závaznému prohlášení o vyloučení
>> > odpovědnosti: *https://www.precheza.cz/01-dovetek/
>> > <https://www.precheza.cz/01-dovetek/>* | This email and any documents
>> > attached to it may be confidential and are subject to the legally
>> binding
>> > disclaimer: *https://www.precheza.cz/en/01-disclaimer/
>> > <https://www.precheza.cz/en/01-disclaimer/>*
>> >
>> >
>> >
>> > *From:* Anupam Tyagi 
>> > *Sent:* Friday, July 7, 2023 12:48 PM
>> > *To:* PIKAL Petr 
>> > *Cc:* r-help@r-project.org
>> > *Subject:* Re: [R] Plotting factors in graph panel
>> >
>> >
>> >
>> > Thanks! You are correct, the graphs look very similar, except ggplot is
>> > scaling the text font to make it more readable. Is there a way to scale
>> > down the x-axis labels, so they are readable?
>> >
>> >
>> >
>> > On Fri, 7 Jul 2023 at 12:02, PIKAL Petr  wrote:
>> >
>> > Hallo Anupam
>> >
>> > I do not see much difference in ggplot or lattice, they seems to me
>> > provide almost identical results when removing theme part from ggplot.
>> >
>> > library(ggplot2)
>> > library(lattice)
>> >
>> > ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) +
>> geom_point()
>> > +
>> >   geom_line() + facet_wrap(~Measure)
>> >
>> > xyplot(Percent ~ Income | Measure, TrialData4,
>> >type = "o", pch = 16, as.table = TRUE, grid = TRUE)
>> >
>

Re: [R] Plotting factors in graph panel

2023-07-11 Thread Deepayan Sarkar
On Wed, 12 Jul 2023 at 08:57, Anupam Tyagi  wrote:

> Thanks.
> I made a graph in Stata that is close to what I want in R. Stata graph is
> attached. The main differences between Stata and R graphs that I was able
> to make, with ggplot or lattice, is that I have been able to scale y-axis
> of each sub-graph independently in Stata, but not in R. Also, x-axis labels
> are also complete in Stata but not in R. Is there a way to do this in R via
> base-R, ggplot or lattice?


Yes, of course. For lattice, add the argument

scales = list(y = "free")

For ggplot2, change

facet_wrap(~Measure)

to

facet_wrap(~Measure, scale = "free")

-Deepayan

I had initially thought that these types of
> panel graphs are common and should be easy to do, but that is not how this
> is turning out to be. Any help is welcome.
>

> On Fri, 7 Jul 2023 at 17:57, PIKAL Petr  wrote:
>
> > Hallo Anupam
> >
> > With
> >
> > ggplot change axis label size into Google
> >
> > the first answer I got was
> >
> > axis.text theme
> >
> > r - Change size of axes title and labels in ggplot2 - Stack Overflow
> > <
> https://stackoverflow.com/questions/14942681/change-size-of-axes-title-and-labels-in-ggplot2
> >
> >
> >
> >
> > so
> >
> >
> >
> > ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) +
> geom_point()
> > +
> >   geom_line() + facet_wrap(~Measure) +
> > theme(axis.text=element_text(size=5))
> >
> >
> >
> > Should do the trick.
> >
> >
> >
> > S pozdravem | Best Regards
> >
> >
> > *RNDr. Petr PIKAL*Vedoucí Výzkumu a vývoje | Research Manager
> >
> >
> > *PRECHEZA a.s.*nábř. Dr. Edvarda Beneše 1170/24 | 750 02 Přerov | Czech
> > Republic
> > Tel: +420 581 252 256 | GSM: +420 724 008 364
> > petr.pi...@precheza.cz | *www.precheza.cz <https://www.precheza.cz/>*
> >
> > *Osobní údaje: *Informace o zpracování a ochraně osobních údajů
> > obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: *
> https://www.precheza.cz/zasady-ochrany-osobnich-udaju/
> > <https://www.precheza.cz/zasady-ochrany-osobnich-udaju/>* | Information
> > about processing and protection of business partner’s personal data are
> > available on website: *
> https://www.precheza.cz/en/personal-data-protection-principles/
> > <https://www.precheza.cz/en/personal-data-protection-principles/>*
> >
> > *Důvěrnost: *Tento e-mail a jakékoliv k němu připojené dokumenty jsou
> > důvěrné a podléhají tomuto právně závaznému prohlášení o vyloučení
> > odpovědnosti: *https://www.precheza.cz/01-dovetek/
> > <https://www.precheza.cz/01-dovetek/>* | This email and any documents
> > attached to it may be confidential and are subject to the legally binding
> > disclaimer: *https://www.precheza.cz/en/01-disclaimer/
> > <https://www.precheza.cz/en/01-disclaimer/>*
> >
> >
> >
> > *From:* Anupam Tyagi 
> > *Sent:* Friday, July 7, 2023 12:48 PM
> > *To:* PIKAL Petr 
> > *Cc:* r-help@r-project.org
> > *Subject:* Re: [R] Plotting factors in graph panel
> >
> >
> >
> > Thanks! You are correct, the graphs look very similar, except ggplot is
> > scaling the text font to make it more readable. Is there a way to scale
> > down the x-axis labels, so they are readable?
> >
> >
> >
> > On Fri, 7 Jul 2023 at 12:02, PIKAL Petr  wrote:
> >
> > Hallo Anupam
> >
> > I do not see much difference in ggplot or lattice, they seems to me
> > provide almost identical results when removing theme part from ggplot.
> >
> > library(ggplot2)
> > library(lattice)
> >
> > ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) +
> geom_point()
> > +
> >   geom_line() + facet_wrap(~Measure)
> >
> > xyplot(Percent ~ Income | Measure, TrialData4,
> >type = "o", pch = 16, as.table = TRUE, grid = TRUE)
> >
> > So it is probably only matter of your preference which one do you choose.
> >
> > Cheers
> > Petr
> >
> >
> > > -Original Message-
> > > From: R-help  On Behalf Of Deepayan
> Sarkar
> > > Sent: Thursday, July 6, 2023 3:06 PM
> > > To: Anupam Tyagi 
> > > Cc: r-help@r-project.org
> > > Subject: Re: [R] Plotting factors in graph panel
> > >
> > > On Thu, 6 Jul 2023 at 15:21, Anupam Tyagi  wrote:
> > > >
> > > > Btw, I think "lattice" graphics will provide a better solution than
> > > > &q

Re: [R] Plotting factors in graph panel

2023-07-11 Thread Anupam Tyagi
Thanks.
I made a graph in Stata that is close to what I want in R. Stata graph is
attached. The main differences between Stata and R graphs that I was able
to make, with ggplot or lattice, is that I have been able to scale y-axis
of each sub-graph independently in Stata, but not in R. Also, x-axis labels
are also complete in Stata but not in R. Is there a way to do this in R via
base-R, ggplot or lattice? I had initially thought that these types of
panel graphs are common and should be easy to do, but that is not how this
is turning out to be. Any help is welcome.

On Fri, 7 Jul 2023 at 17:57, PIKAL Petr  wrote:

> Hallo Anupam
>
> With
>
> ggplot change axis label size into Google
>
> the first answer I got was
>
> axis.text theme
>
> r - Change size of axes title and labels in ggplot2 - Stack Overflow
> <https://stackoverflow.com/questions/14942681/change-size-of-axes-title-and-labels-in-ggplot2>
>
>
>
> so
>
>
>
> ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) + geom_point()
> +
>   geom_line() + facet_wrap(~Measure) +
> theme(axis.text=element_text(size=5))
>
>
>
> Should do the trick.
>
>
>
> S pozdravem | Best Regards
>
>
> *RNDr. Petr PIKAL*Vedoucí Výzkumu a vývoje | Research Manager
>
>
> *PRECHEZA a.s.*nábř. Dr. Edvarda Beneše 1170/24 | 750 02 Přerov | Czech
> Republic
> Tel: +420 581 252 256 | GSM: +420 724 008 364
> petr.pi...@precheza.cz | *www.precheza.cz <https://www.precheza.cz/>*
>
> *Osobní údaje: *Informace o zpracování a ochraně osobních údajů
> obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: 
> *https://www.precheza.cz/zasady-ochrany-osobnich-udaju/
> <https://www.precheza.cz/zasady-ochrany-osobnich-udaju/>* | Information
> about processing and protection of business partner’s personal data are
> available on website: 
> *https://www.precheza.cz/en/personal-data-protection-principles/
> <https://www.precheza.cz/en/personal-data-protection-principles/>*
>
> *Důvěrnost: *Tento e-mail a jakékoliv k němu připojené dokumenty jsou
> důvěrné a podléhají tomuto právně závaznému prohlášení o vyloučení
> odpovědnosti: *https://www.precheza.cz/01-dovetek/
> <https://www.precheza.cz/01-dovetek/>* | This email and any documents
> attached to it may be confidential and are subject to the legally binding
> disclaimer: *https://www.precheza.cz/en/01-disclaimer/
> <https://www.precheza.cz/en/01-disclaimer/>*
>
>
>
> *From:* Anupam Tyagi 
> *Sent:* Friday, July 7, 2023 12:48 PM
> *To:* PIKAL Petr 
> *Cc:* r-help@r-project.org
> *Subject:* Re: [R] Plotting factors in graph panel
>
>
>
> Thanks! You are correct, the graphs look very similar, except ggplot is
> scaling the text font to make it more readable. Is there a way to scale
> down the x-axis labels, so they are readable?
>
>
>
> On Fri, 7 Jul 2023 at 12:02, PIKAL Petr  wrote:
>
> Hallo Anupam
>
> I do not see much difference in ggplot or lattice, they seems to me
> provide almost identical results when removing theme part from ggplot.
>
> library(ggplot2)
> library(lattice)
>
> ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) + geom_point()
> +
>   geom_line() + facet_wrap(~Measure)
>
> xyplot(Percent ~ Income | Measure, TrialData4,
>type = "o", pch = 16, as.table = TRUE, grid = TRUE)
>
> So it is probably only matter of your preference which one do you choose.
>
> Cheers
> Petr
>
>
> > -Original Message-
> > From: R-help  On Behalf Of Deepayan Sarkar
> > Sent: Thursday, July 6, 2023 3:06 PM
> > To: Anupam Tyagi 
> > Cc: r-help@r-project.org
> > Subject: Re: [R] Plotting factors in graph panel
> >
> > On Thu, 6 Jul 2023 at 15:21, Anupam Tyagi  wrote:
> > >
> > > Btw, I think "lattice" graphics will provide a better solution than
> > > "ggplot", because it puts appropriate (space saving) markers on the
> > > axes and does axes labels well. However, I cannot figure out how to do
> > > it in "lattice".
> >
> > You will need to convert Income to a factor first. Alternatively, use
> > dotplot() instead of xyplot(), but that will sort the levels wrongly, so
> better to
> > make the factor first anyway.
> >
> > TrialData4 <- within(TrialData4,
> > {
> > Income <- factor(Income, levels = c("$10", "$25", "$40", "$75", ">
> $75"))
> > })
> >
> > xyplot(Percent ~ Income | Measure, TrialData4,
> >type = "o", pch = 16, as.table = TRUE, grid = TRUE)
> >
> > or
> >
> > dotplot(Percen

Re: [R] Plotting factors in graph panel

2023-07-07 Thread PIKAL Petr
Hallo Anupam

With

ggplot change axis label size into Google

the first answer I got was

axis.text theme

r - Change size of axes title and labels in ggplot2 - Stack Overflow 
<https://stackoverflow.com/questions/14942681/change-size-of-axes-title-and-labels-in-ggplot2>
 

 

so

 

ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) + geom_point() +
  geom_line() + facet_wrap(~Measure) + theme(axis.text=element_text(size=5))

 

Should do the trick.

 

S pozdravem | Best Regards

RNDr. Petr PIKAL
Vedoucí Výzkumu a vývoje | Research Manager

PRECHEZA a.s.
nábř. Dr. Edvarda Beneše 1170/24 | 750 02 Přerov | Czech Republic
Tel: +420 581 252 256 | GSM: +420 724 008 364
 <mailto:petr.pi...@precheza.cz> petr.pi...@precheza.cz |  
<https://www.precheza.cz/> www.precheza.cz

Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na:  
<https://www.precheza.cz/zasady-ochrany-osobnich-udaju/> 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website:  <https://www.precheza.cz/en/personal-data-protection-principles/> 
https://www.precheza.cz/en/personal-data-protection-principles/

Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohlášení o vyloučení odpovědnosti:  
<https://www.precheza.cz/01-dovetek/> https://www.precheza.cz/01-dovetek/ | 
This email and any documents attached to it may be confidential and are subject 
to the legally binding disclaimer:  <https://www.precheza.cz/en/01-disclaimer/> 
https://www.precheza.cz/en/01-disclaimer/

 

From: Anupam Tyagi  
Sent: Friday, July 7, 2023 12:48 PM
To: PIKAL Petr 
Cc: r-help@r-project.org
Subject: Re: [R] Plotting factors in graph panel

 

Thanks! You are correct, the graphs look very similar, except ggplot is scaling 
the text font to make it more readable. Is there a way to scale down the x-axis 
labels, so they are readable?

 

On Fri, 7 Jul 2023 at 12:02, PIKAL Petr mailto:petr.pi...@precheza.cz> > wrote:

Hallo Anupam

I do not see much difference in ggplot or lattice, they seems to me provide 
almost identical results when removing theme part from ggplot.

library(ggplot2)
library(lattice)

ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) + geom_point() +
  geom_line() + facet_wrap(~Measure)

xyplot(Percent ~ Income | Measure, TrialData4,
   type = "o", pch = 16, as.table = TRUE, grid = TRUE)

So it is probably only matter of your preference which one do you choose.

Cheers
Petr


> -Original Message-
> From: R-help  <mailto:r-help-boun...@r-project.org> > On Behalf Of Deepayan Sarkar
> Sent: Thursday, July 6, 2023 3:06 PM
> To: Anupam Tyagi mailto:anupty...@gmail.com> >
> Cc: r-help@r-project.org <mailto:r-help@r-project.org> 
> Subject: Re: [R] Plotting factors in graph panel
> 
> On Thu, 6 Jul 2023 at 15:21, Anupam Tyagi  <mailto:anupty...@gmail.com> > wrote:
> >
> > Btw, I think "lattice" graphics will provide a better solution than
> > "ggplot", because it puts appropriate (space saving) markers on the
> > axes and does axes labels well. However, I cannot figure out how to do
> > it in "lattice".
> 
> You will need to convert Income to a factor first. Alternatively, use
> dotplot() instead of xyplot(), but that will sort the levels wrongly, so 
> better to
> make the factor first anyway.
> 
> TrialData4 <- within(TrialData4,
> {
> Income <- factor(Income, levels = c("$10", "$25", "$40", "$75", "> $75"))
> })
> 
> xyplot(Percent ~ Income | Measure, TrialData4,
>type = "o", pch = 16, as.table = TRUE, grid = TRUE)
> 
> or
> 
> dotplot(Percent ~ Income | Measure, TrialData4,
> type = "o", as.table = TRUE)
> 
> This is not really any different from the ggplot() version though.
> Maybe you just don't like the effect of the '+ theme_classic()' part.
> 
> Best,
> -Deepayan
> 
> 
> > On Thu, 6 Jul 2023 at 15:11, Anupam Tyagi  > <mailto:anupty...@gmail.com> > wrote:
> >
> > > Hi John:
> > >
> > > Thanks! Below is the data using your suggestion. I used "ggplot" to
> > > make a graph. I am not too happy with it. I am looking for something
> > > simpler and cleaner. Plot is attached.
> > >
> > > I also tried "lattice" package, but nothing got plotted with "xyplot"
> > > command, because it is looking for a numeric variable on x-axis.
> > >
> > > ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) +
>

Re: [R] Plotting factors in graph panel

2023-07-07 Thread Anupam Tyagi
Thanks! You are correct, the graphs look very similar, except ggplot is
scaling the text font to make it more readable. Is there a way to scale
down the x-axis labels, so they are readable?

On Fri, 7 Jul 2023 at 12:02, PIKAL Petr  wrote:

> Hallo Anupam
>
> I do not see much difference in ggplot or lattice, they seems to me
> provide almost identical results when removing theme part from ggplot.
>
> library(ggplot2)
> library(lattice)
>
> ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) + geom_point()
> +
>   geom_line() + facet_wrap(~Measure)
>
> xyplot(Percent ~ Income | Measure, TrialData4,
>type = "o", pch = 16, as.table = TRUE, grid = TRUE)
>
> So it is probably only matter of your preference which one do you choose.
>
> Cheers
> Petr
>
>
> > -Original Message-
> > From: R-help  On Behalf Of Deepayan Sarkar
> > Sent: Thursday, July 6, 2023 3:06 PM
> > To: Anupam Tyagi 
> > Cc: r-help@r-project.org
> > Subject: Re: [R] Plotting factors in graph panel
> >
> > On Thu, 6 Jul 2023 at 15:21, Anupam Tyagi  wrote:
> > >
> > > Btw, I think "lattice" graphics will provide a better solution than
> > > "ggplot", because it puts appropriate (space saving) markers on the
> > > axes and does axes labels well. However, I cannot figure out how to do
> > > it in "lattice".
> >
> > You will need to convert Income to a factor first. Alternatively, use
> > dotplot() instead of xyplot(), but that will sort the levels wrongly, so
> better to
> > make the factor first anyway.
> >
> > TrialData4 <- within(TrialData4,
> > {
> > Income <- factor(Income, levels = c("$10", "$25", "$40", "$75", ">
> $75"))
> > })
> >
> > xyplot(Percent ~ Income | Measure, TrialData4,
> >type = "o", pch = 16, as.table = TRUE, grid = TRUE)
> >
> > or
> >
> > dotplot(Percent ~ Income | Measure, TrialData4,
> > type = "o", as.table = TRUE)
> >
> > This is not really any different from the ggplot() version though.
> > Maybe you just don't like the effect of the '+ theme_classic()' part.
> >
> > Best,
> > -Deepayan
> >
> >
> > > On Thu, 6 Jul 2023 at 15:11, Anupam Tyagi  wrote:
> > >
> > > > Hi John:
> > > >
> > > > Thanks! Below is the data using your suggestion. I used "ggplot" to
> > > > make a graph. I am not too happy with it. I am looking for something
> > > > simpler and cleaner. Plot is attached.
> > > >
> > > > I also tried "lattice" package, but nothing got plotted with "xyplot"
> > > > command, because it is looking for a numeric variable on x-axis.
> > > >
> > > > ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) +
> > > > geom_point()
> > > > +
> > > >   geom_line() + facet_wrap(~Measure) + theme_classic()
> > > >
> > > > > dput(TrialData4)structure(list(Income = c("$10", "$25", "$40",
> > > > > "$75", "> $75",
> > > > "$10", "$25", "$40", "$75", "> $75", "$10", "$25", "$40", "$75", ">
> > > > $75", "$10", "$25", "$40", "$75", "> $75", "$10", "$25", "$40",
> > > > "$75", "> $75", "$10", "$25", "$40", "$75", "> $75", "$10", "$25",
> > > > "$40", "$75", "> $75", "$10", "$25", "$40", "$75", "> $75", "$10",
> > > > "$25", "$40", "$75", "> $75", "$10", "$25", "$40", "$75", "> $75",
> > > > "$10", "$25", "$40", "$75", "> $75", "$10", "$25", "$40", "$75", ">
> > > > $75", "$10", "$25", "$40", "$75", "> $75", "$10", "$25", "$40",
> > > > "$75", "> $75", "$10", "$25", "$40", "$75", "> $75", "$10", "$25",
> > > > "

Re: [R] Plotting factors in graph panel

2023-07-07 Thread Anupam Tyagi
ot;$40", "$75", "> $75", "$10", "$25",
> > > "$40", "$75", "> $75", "$10", "$25", "$40", "$75", "> $75", "$10",
> > > "$25", "$40", "$75", "> $75", "$10", "$25", "$40", "$75", "> $75"
> > > ), Percent = c(3.052, 2.292, 2.244, 1.706, 1.297, 29.76, 28.79,
> > > 29.51, 28.9, 31.67, 31.18, 32.64, 34.31, 35.65, 37.59, 36, 36.27,
> > > 33.94, 33.74, 29.44, 46.54, 54.01, 59.1, 62.17, 67.67, 24.75,
> > > 24.4, 25, 24.61, 24.02, 25.4, 18.7, 29, 11.48, 7.103, 3.052,
> > > 2.292, 2.244, 1.706, 1.297, 29.76, 28.79, 29.51, 28.9, 31.67,
> > > 31.18, 32.64, 34.31, 35.65, 37.59, 36, 36.27, 33.94, 33.74, 29.44,
> > > 46.54, 54.01, 59.1, 62.17, 67.67, 24.75, 24.4, 25, 24.61, 24.02,
> > > 25.4, 18.7, 29, 11.48, 7.103, 3.052, 2.292, 2.244, 1.706, 1.297,
> > > 29.76, 28.79, 29.51, 28.9, 31.67, 31.18, 32.64, 34.31, 35.65,
> > > 37.59, 36, 36.27, 33.94, 33.74, 29.44, 46.54, 54.01, 59.1, 62.17,
> > > 67.67, 24.75, 24.4, 25, 24.61, 24.02, 25.4, 18.7, 29, 11.48,
> > > 7.103, 3.052, 2.292, 2.244, 1.706, 1.297, 29.76, 28.79, 29.51,
> > > 28.9, 31.67, 31.18, 32.64, 34.31, 35.65, 37.59, 36, 36.27, 33.94,
> > > 33.74, 29.44, 46.54, 54.01, 59.1, 62.17, 67.67, 24.75, 24.4,
> > > 25, 24.61, 24.02, 25.4, 18.7, 29, 11.48, 7.103), Measure = c("MF None",
> > > "MF None", "MF None", "MF None", "MF None", "MF Equity", "MF Equity",
> > > "MF Equity", "MF Equity", "MF Equity", "MF Debt", "MF Debt",
> > > "MF Debt", "MF Debt", "MF Debt", "MF Hybrid", "MF Hybrid", "MF Hybrid",
> > > "MF Hybrid", "MF Hybrid", "Bank None", "Bank None", "Bank None",
> > > "Bank None", "Bank None", "Bank Current", "Bank Current", "Bank
> Current",
> > > "Bank Current", "Bank Current", "Bank Savings", "Bank Savings",
> > > "Bank Savings", "Bank Savings", "Bank Savings", "MF None 1",
> > > "MF None 1", "MF None 1", "MF None 1", "MF None 1", "MF Equity 1",
> > > "MF Equity 1", "MF Equity 1", "MF Equity 1", "MF Equity 1", "MF Debt
> 1",
> > > "MF Debt 1", "MF Debt 1", "MF Debt 1", "MF Debt 1", "MF Hybrid 1",
> > > "MF Hybrid 1", "MF Hybrid 1", "MF Hybrid 1", "MF Hybrid 1", "Bank None
> 1",
> > > "Bank None 1", "Bank None 1", "Bank None 1", "Bank None 1", "Bank
> Current 1",
> > > "Bank Current 1", "Bank Current 1", "Bank Current 1", "Bank Current 1",
> > > "Bank Savings 1", "Bank Savings 1", "Bank Savings 1", "Bank Savings 1",
> > > "Bank Savings 1", "MF None 2", "MF None 2", "MF None 2", "MF None 2",
> > > "MF None 2", "MF Equity 2", "MF Equity 2", "MF Equity 2", "MF Equity
> 2",
> > > "MF Equity 2", "MF Debt 2", "MF Debt 2", "MF Debt 2", "MF Debt 2",
> > > "MF Debt 2", "MF Hybrid 2", "MF Hybrid 2", "MF Hybrid 2", "MF Hybrid
> 2",
> > > "MF Hybrid 2", "Bank None 2", "Bank None 2", "Bank None 2", "Bank None
> 2",
> > > "Bank None 2", "Bank Current 2", "Bank Current 2", "Bank Current 2",
> > > "Bank Current 2", "Bank Current 2", "Bank Savings 2", "Bank Savings 2",
> > > "Bank Savings 2", "Bank Savings 2", "Bank Savings 2", "MF None 3",
> > > "MF None 3", "MF None 3", "MF None 3", "MF None 3", "MF Equity 3",
> > > "MF Equity 3", "MF Equity 3", "MF Equity 3", "MF Equity 3", "MF Debt
> 3",
> > > "MF Debt 3", "MF Debt 3", "MF Debt 3", "MF Debt 3", "MF Hybrid 3&q

Re: [R] Plotting factors in graph panel

2023-07-07 Thread PIKAL Petr
Hallo Anupam

I do not see much difference in ggplot or lattice, they seems to me provide 
almost identical results when removing theme part from ggplot.

library(ggplot2)
library(lattice)

ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) + geom_point() +
  geom_line() + facet_wrap(~Measure)

xyplot(Percent ~ Income | Measure, TrialData4,
   type = "o", pch = 16, as.table = TRUE, grid = TRUE)

So it is probably only matter of your preference which one do you choose.

Cheers
Petr


> -Original Message-
> From: R-help  On Behalf Of Deepayan Sarkar
> Sent: Thursday, July 6, 2023 3:06 PM
> To: Anupam Tyagi 
> Cc: r-help@r-project.org
> Subject: Re: [R] Plotting factors in graph panel
> 
> On Thu, 6 Jul 2023 at 15:21, Anupam Tyagi  wrote:
> >
> > Btw, I think "lattice" graphics will provide a better solution than
> > "ggplot", because it puts appropriate (space saving) markers on the
> > axes and does axes labels well. However, I cannot figure out how to do
> > it in "lattice".
> 
> You will need to convert Income to a factor first. Alternatively, use
> dotplot() instead of xyplot(), but that will sort the levels wrongly, so 
> better to
> make the factor first anyway.
> 
> TrialData4 <- within(TrialData4,
> {
> Income <- factor(Income, levels = c("$10", "$25", "$40", "$75", "> $75"))
> })
> 
> xyplot(Percent ~ Income | Measure, TrialData4,
>type = "o", pch = 16, as.table = TRUE, grid = TRUE)
> 
> or
> 
> dotplot(Percent ~ Income | Measure, TrialData4,
> type = "o", as.table = TRUE)
> 
> This is not really any different from the ggplot() version though.
> Maybe you just don't like the effect of the '+ theme_classic()' part.
> 
> Best,
> -Deepayan
> 
> 
> > On Thu, 6 Jul 2023 at 15:11, Anupam Tyagi  wrote:
> >
> > > Hi John:
> > >
> > > Thanks! Below is the data using your suggestion. I used "ggplot" to
> > > make a graph. I am not too happy with it. I am looking for something
> > > simpler and cleaner. Plot is attached.
> > >
> > > I also tried "lattice" package, but nothing got plotted with "xyplot"
> > > command, because it is looking for a numeric variable on x-axis.
> > >
> > > ggplot(TrialData4, aes(x=Income, y=Percent, group=Measure)) +
> > > geom_point()
> > > +
> > >   geom_line() + facet_wrap(~Measure) + theme_classic()
> > >
> > > > dput(TrialData4)structure(list(Income = c("$10", "$25", "$40",
> > > > "$75", "> $75",
> > > "$10", "$25", "$40", "$75", "> $75", "$10", "$25", "$40", "$75", ">
> > > $75", "$10", "$25", "$40", "$75", "> $75", "$10", "$25", "$40",
> > > "$75", "> $75", "$10", "$25", "$40", "$75", "> $75", "$10", "$25",
> > > "$40", "$75", "> $75", "$10", "$25", "$40", "$75", "> $75", "$10",
> > > "$25", "$40", "$75", "> $75", "$10", "$25", "$40", "$75", "> $75",
> > > "$10", "$25", "$40", "$75", "> $75", "$10", "$25", "$40", "$75", ">
> > > $75", "$10", "$25", "$40", "$75", "> $75", "$10", "$25", "$40",
> > > "$75", "> $75", "$10", "$25", "$40", "$75", "> $75", "$10", "$25",
> > > "$40", "$75", "> $75", "$10", "$25", "$40", "$75", "> $75", "$10",
> > > "$25", "$40", "$75", "> $75", "$10", "$25", "$40", "$75", "> $75",
> > > "$10", "$25", "$40", "$75", "> $75", "$10", "$25", "$40", "$75", ">
> > > $75", "$10", "$25", "$40", "$75", "> $75", "$10", "

Re: [R] Plotting factors in graph panel

2023-07-06 Thread Deepayan Sarkar
 > 25.4, 18.7, 29, 11.48, 7.103, 3.052, 2.292, 2.244, 1.706, 1.297,
> > 29.76, 28.79, 29.51, 28.9, 31.67, 31.18, 32.64, 34.31, 35.65,
> > 37.59, 36, 36.27, 33.94, 33.74, 29.44, 46.54, 54.01, 59.1, 62.17,
> > 67.67, 24.75, 24.4, 25, 24.61, 24.02, 25.4, 18.7, 29, 11.48,
> > 7.103, 3.052, 2.292, 2.244, 1.706, 1.297, 29.76, 28.79, 29.51,
> > 28.9, 31.67, 31.18, 32.64, 34.31, 35.65, 37.59, 36, 36.27, 33.94,
> > 33.74, 29.44, 46.54, 54.01, 59.1, 62.17, 67.67, 24.75, 24.4,
> > 25, 24.61, 24.02, 25.4, 18.7, 29, 11.48, 7.103), Measure = c("MF None",
> > "MF None", "MF None", "MF None", "MF None", "MF Equity", "MF Equity",
> > "MF Equity", "MF Equity", "MF Equity", "MF Debt", "MF Debt",
> > "MF Debt", "MF Debt", "MF Debt", "MF Hybrid", "MF Hybrid", "MF Hybrid",
> > "MF Hybrid", "MF Hybrid", "Bank None", "Bank None", "Bank None",
> > "Bank None", "Bank None", "Bank Current", "Bank Current", "Bank Current",
> > "Bank Current", "Bank Current", "Bank Savings", "Bank Savings",
> > "Bank Savings", "Bank Savings", "Bank Savings", "MF None 1",
> > "MF None 1", "MF None 1", "MF None 1", "MF None 1", "MF Equity 1",
> > "MF Equity 1", "MF Equity 1", "MF Equity 1", "MF Equity 1", "MF Debt 1",
> > "MF Debt 1", "MF Debt 1", "MF Debt 1", "MF Debt 1", "MF Hybrid 1",
> > "MF Hybrid 1", "MF Hybrid 1", "MF Hybrid 1", "MF Hybrid 1", "Bank None 1",
> > "Bank None 1", "Bank None 1", "Bank None 1", "Bank None 1", "Bank Current 
> > 1",
> > "Bank Current 1", "Bank Current 1", "Bank Current 1", "Bank Current 1",
> > "Bank Savings 1", "Bank Savings 1", "Bank Savings 1", "Bank Savings 1",
> > "Bank Savings 1", "MF None 2", "MF None 2", "MF None 2", "MF None 2",
> > "MF None 2", "MF Equity 2", "MF Equity 2", "MF Equity 2", "MF Equity 2",
> > "MF Equity 2", "MF Debt 2", "MF Debt 2", "MF Debt 2", "MF Debt 2",
> > "MF Debt 2", "MF Hybrid 2", "MF Hybrid 2", "MF Hybrid 2", "MF Hybrid 2",
> > "MF Hybrid 2", "Bank None 2", "Bank None 2", "Bank None 2", "Bank None 2",
> > "Bank None 2", "Bank Current 2", "Bank Current 2", "Bank Current 2",
> > "Bank Current 2", "Bank Current 2", "Bank Savings 2", "Bank Savings 2",
> > "Bank Savings 2", "Bank Savings 2", "Bank Savings 2", "MF None 3",
> > "MF None 3", "MF None 3", "MF None 3", "MF None 3", "MF Equity 3",
> > "MF Equity 3", "MF Equity 3", "MF Equity 3", "MF Equity 3", "MF Debt 3",
> > "MF Debt 3", "MF Debt 3", "MF Debt 3", "MF Debt 3", "MF Hybrid 3",
> > "MF Hybrid 3", "MF Hybrid 3", "MF Hybrid 3", "MF Hybrid 3", "Bank None 3",
> > "Bank None 3", "Bank None 3", "Bank None 3", "Bank None 3", "Bank Current 
> > 3",
> > "Bank Current 3", "Bank Current 3", "Bank Current 3", "Bank Current 3",
> > "Bank Savings 3", "Bank Savings 3", "Bank Savings 3", "Bank Savings 3",
> > "Bank Savings 3")), class = c("tbl_df", "tbl", "data.frame"), row.names = 
> > c(NA,
> > -140L))
> >
> >
> >
> >
> > On Thu, 29 Jun 2023 at 21:11, John Kane  wrote:
> >
> >> Anupa,
> >>
> >> I think your  best bet with your data would be to tidy it up in Excel,
> >> read it into  R using something like the readxl package and then supply
> >> some sample data is the dput() function.
> >>
> >> In the case of a large dataset something like dput(head(mydata, 100))
> >> should supply the dat

Re: [R] Plotting factors in graph panel

2023-07-06 Thread Anupam Tyagi
t;, "Bank None", "Bank None", "Bank None",
> "Bank None", "Bank None", "Bank Current", "Bank Current", "Bank Current",
> "Bank Current", "Bank Current", "Bank Savings", "Bank Savings",
> "Bank Savings", "Bank Savings", "Bank Savings", "MF None 1",
> "MF None 1", "MF None 1", "MF None 1", "MF None 1", "MF Equity 1",
> "MF Equity 1", "MF Equity 1", "MF Equity 1", "MF Equity 1", "MF Debt 1",
> "MF Debt 1", "MF Debt 1", "MF Debt 1", "MF Debt 1", "MF Hybrid 1",
> "MF Hybrid 1", "MF Hybrid 1", "MF Hybrid 1", "MF Hybrid 1", "Bank None 1",
> "Bank None 1", "Bank None 1", "Bank None 1", "Bank None 1", "Bank Current 1",
> "Bank Current 1", "Bank Current 1", "Bank Current 1", "Bank Current 1",
> "Bank Savings 1", "Bank Savings 1", "Bank Savings 1", "Bank Savings 1",
> "Bank Savings 1", "MF None 2", "MF None 2", "MF None 2", "MF None 2",
> "MF None 2", "MF Equity 2", "MF Equity 2", "MF Equity 2", "MF Equity 2",
> "MF Equity 2", "MF Debt 2", "MF Debt 2", "MF Debt 2", "MF Debt 2",
> "MF Debt 2", "MF Hybrid 2", "MF Hybrid 2", "MF Hybrid 2", "MF Hybrid 2",
> "MF Hybrid 2", "Bank None 2", "Bank None 2", "Bank None 2", "Bank None 2",
> "Bank None 2", "Bank Current 2", "Bank Current 2", "Bank Current 2",
> "Bank Current 2", "Bank Current 2", "Bank Savings 2", "Bank Savings 2",
> "Bank Savings 2", "Bank Savings 2", "Bank Savings 2", "MF None 3",
> "MF None 3", "MF None 3", "MF None 3", "MF None 3", "MF Equity 3",
> "MF Equity 3", "MF Equity 3", "MF Equity 3", "MF Equity 3", "MF Debt 3",
> "MF Debt 3", "MF Debt 3", "MF Debt 3", "MF Debt 3", "MF Hybrid 3",
> "MF Hybrid 3", "MF Hybrid 3", "MF Hybrid 3", "MF Hybrid 3", "Bank None 3",
> "Bank None 3", "Bank None 3", "Bank None 3", "Bank None 3", "Bank Current 3",
> "Bank Current 3", "Bank Current 3", "Bank Current 3", "Bank Current 3",
> "Bank Savings 3", "Bank Savings 3", "Bank Savings 3", "Bank Savings 3",
> "Bank Savings 3")), class = c("tbl_df", "tbl", "data.frame"), row.names = 
> c(NA,
> -140L))
>
>
>
>
> On Thu, 29 Jun 2023 at 21:11, John Kane  wrote:
>
>> Anupa,
>>
>> I think your  best bet with your data would be to tidy it up in Excel,
>> read it into  R using something like the readxl package and then supply
>> some sample data is the dput() function.
>>
>> In the case of a large dataset something like dput(head(mydata, 100))
>> should supply the data we need. Just do dput(mydata) where *mydata* is your
>> data. Copy the output and paste it here.
>>
>> On Thu, 29 Jun 2023 at 08:37, Ebert,Timothy Aaron  wrote:
>>
>>> Reposting the data did not help. We do not like to guess, and doing so
>>> takes a great deal of time that is likely wasted.
>>> Rows are observations.
>>> Columns are variables.
>>> In Excel, the first row will be variable names and all subsequent rows
>>> will be observations.
>>>
>>> Income is the first variable. It has seven states: $10, $25, $40, $75,
>>> >$75, "No", "Answer"
>>> MF is the second variable. It has six values: 1, 2, 3, 4, 5, 9
>>> None is the third variable. It has seven values: 1, 3.05,  2.29, 2.24,
>>> 1.71, 1.30, 2.83
>>> Equity is the last variable with many states, both numeric and text. A
>>> computer will read it all as text.
>>>
>>> As written the data cannot be analyzed.
>>>
>>> Equity looks like it should be numeric. However, it has text values:
>>> "Debt", "Hybrid", Bank", "AC", "None", "Current", "Savings&

Re: [R] Plotting factors in graph panel

2023-07-06 Thread Anupam Tyagi
ity 1", "MF Equity 1", "MF Equity 1", "MF Debt 1",
"MF Debt 1", "MF Debt 1", "MF Debt 1", "MF Debt 1", "MF Hybrid 1",
"MF Hybrid 1", "MF Hybrid 1", "MF Hybrid 1", "MF Hybrid 1", "Bank None 1",
"Bank None 1", "Bank None 1", "Bank None 1", "Bank None 1", "Bank Current 1",
"Bank Current 1", "Bank Current 1", "Bank Current 1", "Bank Current 1",
"Bank Savings 1", "Bank Savings 1", "Bank Savings 1", "Bank Savings 1",
"Bank Savings 1", "MF None 2", "MF None 2", "MF None 2", "MF None 2",
"MF None 2", "MF Equity 2", "MF Equity 2", "MF Equity 2", "MF Equity 2",
"MF Equity 2", "MF Debt 2", "MF Debt 2", "MF Debt 2", "MF Debt 2",
"MF Debt 2", "MF Hybrid 2", "MF Hybrid 2", "MF Hybrid 2", "MF Hybrid 2",
"MF Hybrid 2", "Bank None 2", "Bank None 2", "Bank None 2", "Bank None 2",
"Bank None 2", "Bank Current 2", "Bank Current 2", "Bank Current 2",
"Bank Current 2", "Bank Current 2", "Bank Savings 2", "Bank Savings 2",
"Bank Savings 2", "Bank Savings 2", "Bank Savings 2", "MF None 3",
"MF None 3", "MF None 3", "MF None 3", "MF None 3", "MF Equity 3",
"MF Equity 3", "MF Equity 3", "MF Equity 3", "MF Equity 3", "MF Debt 3",
"MF Debt 3", "MF Debt 3", "MF Debt 3", "MF Debt 3", "MF Hybrid 3",
"MF Hybrid 3", "MF Hybrid 3", "MF Hybrid 3", "MF Hybrid 3", "Bank None 3",
"Bank None 3", "Bank None 3", "Bank None 3", "Bank None 3", "Bank Current 3",
"Bank Current 3", "Bank Current 3", "Bank Current 3", "Bank Current 3",
"Bank Savings 3", "Bank Savings 3", "Bank Savings 3", "Bank Savings 3",
"Bank Savings 3")), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-140L))




On Thu, 29 Jun 2023 at 21:11, John Kane  wrote:

> Anupa,
>
> I think your  best bet with your data would be to tidy it up in Excel,
> read it into  R using something like the readxl package and then supply
> some sample data is the dput() function.
>
> In the case of a large dataset something like dput(head(mydata, 100))
> should supply the data we need. Just do dput(mydata) where *mydata* is your
> data. Copy the output and paste it here.
>
> On Thu, 29 Jun 2023 at 08:37, Ebert,Timothy Aaron  wrote:
>
>> Reposting the data did not help. We do not like to guess, and doing so
>> takes a great deal of time that is likely wasted.
>> Rows are observations.
>> Columns are variables.
>> In Excel, the first row will be variable names and all subsequent rows
>> will be observations.
>>
>> Income is the first variable. It has seven states: $10, $25, $40, $75,
>> >$75, "No", "Answer"
>> MF is the second variable. It has six values: 1, 2, 3, 4, 5, 9
>> None is the third variable. It has seven values: 1, 3.05,  2.29, 2.24,
>> 1.71, 1.30, 2.83
>> Equity is the last variable with many states, both numeric and text. A
>> computer will read it all as text.
>>
>> As written the data cannot be analyzed.
>>
>> Equity looks like it should be numeric. However, it has text values:
>> "Debt", "Hybrid", Bank", "AC", "None", "Current", "Savings", "No", and
>> "Answer"
>>
>> In looking at the data I try to find some organization where every
>> variable has the same number of rows as every other variable. I fail with
>> these data.
>> I could combine "No" and "Answer" into one name "No Answer" to make it
>> agree with MF, but then it does not work for None.
>>
>>
>> Please rework the data in Excel so that we can properly interpret the
>> content. If it is badly organized in Excel, moving it to R will not help.
>> Below, I tried adding carriage returns and spaces to organize the data,
>> but I have a column of numbers that are not identified. The values below
>> $10 do not make much sense compared to other values.
>>
>>

Re: [R] Plotting factors in graph panel

2023-07-05 Thread Anupam Tyagi
I am working with Jim's solution, but I am getting some errors. I organized
the data in Excel and read into R using the Import option in the menu of
R-Studio. For some reason it is telling me my data is a Tibble and not a
dataframe. Am I using Tidyverse unknowingly? I thought I was working in
base-R.


> head(TrialData)# A tibble: 5 × 8
  Income `MF None` `MF Equity` `MF Debt` `MF Hybrid` Bank …¹ Bank …² Bank …³
 
1 $10 3.0529.8  31.236  46.5
24.8   25.4 2 $25 2.2928.8  32.636.3
54.024.4   18.7 3 $40 2.2429.5  34.3
33.959.125 29   4 $75 1.7128.9  35.6
 33.762.224.6   11.5 5 > $75   1.3031.7
37.629.467.724.07.10# … with abbreviated variable
names ¹`Bank None`, ²`Bank Current`,#   ³`Bank Savings`


> png("Income_pcts.png",height=700)> par(mfrow=c(4,1))> plot(TrialData[,"Bank 
> Current"], type="o",lwd=3,main="Bank Current", 
> xlab="Income",ylab="%",xaxt="n")Warning messages:
1: In plot.window(xlim, ylim, log, ...) :
  graphical parameter "type" is obsolete
2: In axis(side = side, at = at, labels = labels, ...) :
  graphical parameter "type" is obsolete
3: In title(xlab = xlab, ylab = ylab, ...) :
  graphical parameter "type" is obsolete


On Fri, 30 Jun 2023 at 04:41, Jim Lemon  wrote:

> Okay. Here is a modification that does four single line plots.
>
> at_df<-read.table(text=
>  "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current
> Bank_Savings Bank_NA
>  $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
>  $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
>  $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
>  $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
>  >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208
>  No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
>  header=TRUE,stringsAsFactors=FALSE)
> at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")]
> png("Income_pcts.png",height=700)
> par(mfrow=c(4,1))
> plot(at_df[,"Bank_Current"],
>  type="l",lwd=3,main="Bsnk_Current",
>  xlab="Income",ylab="%",xaxt="n")
> axis(1,at=1:5,labels=at_df$Income)
> plot(at_df[,"Bank_Savings"],
>  type="l",lwd=3,main="Bank_Sasvings",
>  xlab="Income",ylab="%",xaxt="n")
> axis(1,at=1:5,labels=at_df$Income)
> plot(at_df[,"MF_Equity"],
>  type="l",lwd=3,main="MF_Equity",
>  xlab="Income",ylab="%",xaxt="n")
> axis(1,at=1:5,labels=at_df$Income)
> plot(at_df[,"MF_Debt"],
>  type="l",lwd=3,main="MF_Debt",
>  xlab="Income",ylab="%",xaxt="n")
> axis(1,at=1:5,labels=at_df$Income)
> dev.off()
>
> Jim
>
> On Thu, Jun 29, 2023 at 1:49 PM Anupam Tyagi  wrote:
> >
> > Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have
> > been well.
> >
> > Pikal, thanks. Your solution may be close to what I want. I did not know
> > that I was posting in HTML. I just copied the data from Excel and posted
> in
> > the email in Gmail. The data is still in Excel, because I have not yet
> > figured out what is a good way to organize it in R. I am posting it again
> > below as text. These are rows in Excel: 1,2,3,5,9 after MF are income
> > categories and No Answer category (9). Down the second column are
> > categories of MF and Bank AC. Rest of the columns are percentages.
> >
> > Jim, thanks for the graph. I am looking to plot only one line (category)
> > each in many small plots on the same page. I don't want to compare
> > different categories on the same graph as you do, but see how each
> category
> > varies by income, one category in each graph. Like Excel does with
> > Sparklines (Top menu: Insert, Sparklines, Lines). I have many categories
> > for many variables. I am only showing two MF and Bank AC.
> >
> > Income $10 $25 $40 $75 > $75 No Answer
> > MF 1 2 3 4 5 9
> > None 1 3.05 2.29 2.24 1.71 1.30 2.83
> > Equity 2 29.76 28.79 29.51 28.90 31.67 36.77
> > Debt 3 31.18 32.64 34.31 35.65 37.59 33.15
> > Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25
> > Bank AC
> > None 1 46.54 54.01 59.1 62.17 67.67 60.87
> > Current 2 24.75 24.4 25 24.61 24.02 21.09
> > Savings 3 25.4 18.7 29 11.48 7.103 13.46
> > No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577
> >
> >
> > On Wed, 28 Jun 2023 at 17:30, Jim Lemon  wrote:
> >
> > > Hi Anupam,
> > > Haven't heard from you in a long time. Perhaps you want something like
> > > this:
> > >
> > > at_df<-read.table(text=
> > >  "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current
> > > Bank_Savings Bank_NA
> > >  $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
> > >  $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
> > >  $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
> > >  $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
> > >  >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208
> > >  No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
> > >  header=TRUE,stringsAsFactors=FALSE)
> > > 

Re: [R] Plotting factors in graph panel

2023-07-03 Thread PIKAL Petr
Hi

I believe that facet_grid his is quite close to what you expect.  

p <- ggplot(mpg, aes(displ, cty)) + geom_point()+geom_line()
p + facet_grid(vars(drv), vars(cyl))

You can inspect how mpg data is organized by head(mpg)

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Anupam Tyagi
> Sent: Monday, July 3, 2023 11:54 AM
> To: Jim Lemon 
> Cc: r-help mailing list 
> Subject: Re: [R] Plotting factors in graph panel
> 
> Attached is another example plot, that is better than the earlier one.
> 
> On Mon, 3 Jul 2023 at 15:21, Anupam Tyagi  wrote:
> 
> > I thought maybe I can share with you how the data looks in Excel, and
> > an example plot I found on the web that looks similar to what I want to 
> > plot.
> > These are attached to this email as *.png files. I am trying to see
> > (plot) how each row of data (percentages) varies with income, making
> > many small graphs in the same plot. For each row of data there will be
> > one graph. I can manually delete the "No Answer" rows in Excel, if
> > that is the best solution. I want the output to look like the
> > sparklines in column "I" of attached Excel screenshot, with labelling
> > of each graphs. This is similar to the attached "Example_plot". I
> > thought this could be done with Lattice, or base-R, or ggplot easily,
> > but this turning out to be more difficult than I had thought.
> >
> > On Mon, 3 Jul 2023 at 14:38, Anupam Tyagi  wrote:
> >
> >> Thanks Jim, thanks everyone. I was caught up with work and moving
> >> home, so a delay in response. I tried running the code you provided
> >> and it is not running well in my R-Studio setup. It is giving errors
> >> and not producing plots. I don't yet understand all the code well
> >> yet, so I need to work on it and then get back to you all. Sorry for
> >> not posting data from a R dataframe. My data is still in Excel. I
> >> organized data in Excel almost exactly (look wise) as the output from
> >> Stata log file (text) for a "tabulate" command for a survey dataset.
> >> I don't yet understand a good way to organize this data in R, so I
> >> cannot send it to you now. Let me do some work on this, understand
> >> the R code you have given, and get back to you in a few days. I have
> >> not been using R lately, but I think the graph I am trying to make
> >> will be done better and easier in R than in Stata. Thank you all for all 
> >> your
> help. Let me do some work and get back to you.
> >>
> >>
> >> On Fri, 30 Jun 2023 at 04:41, Jim Lemon  wrote:
> >>
> >>> Okay. Here is a modification that does four single line plots.
> >>>
> >>> at_df<-read.table(text=
> >>>  "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None
> >>> Bank_Current Bank_Savings Bank_NA
> >>>  $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
> >>>  $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
> >>>  $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
> >>>  $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
> >>>  >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208  No_Answer 9
> >>> 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
> >>>  header=TRUE,stringsAsFactors=FALSE)
> >>> at_df<-
> at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA"
> >>> )]
> >>> png("Income_pcts.png",height=700)
> >>> par(mfrow=c(4,1))
> >>> plot(at_df[,"Bank_Current"],
> >>>  type="l",lwd=3,main="Bsnk_Current",
> >>>  xlab="Income",ylab="%",xaxt="n")
> >>> axis(1,at=1:5,labels=at_df$Income)
> >>> plot(at_df[,"Bank_Savings"],
> >>>  type="l",lwd=3,main="Bank_Sasvings",
> >>>  xlab="Income",ylab="%",xaxt="n")
> >>> axis(1,at=1:5,labels=at_df$Income)
> >>> plot(at_df[,"MF_Equity"],
> >>>  type="l",lwd=3,main="MF_Equity",
> >>>  xlab="Income",ylab="%",xaxt="n")
> >>> axis(1,at=1:5,labels=at_df$Income)
> >>> plot(at_df[,"MF_Debt"],
> >>>  type="l",lwd=3,main="MF_Debt",
> >>>  xlab="Income",ylab="%",xaxt="n")
> >>> axis(1,at=1:5,labels=at_df$Income)
> >>> dev.off()
> >>>
> >>> Jim
> &

Re: [R] Plotting factors in graph panel

2023-07-03 Thread Anupam Tyagi
Attached is another example plot, that is better than the earlier one.

On Mon, 3 Jul 2023 at 15:21, Anupam Tyagi  wrote:

> I thought maybe I can share with you how the data looks in Excel, and an
> example plot I found on the web that looks similar to what I want to plot.
> These are attached to this email as *.png files. I am trying to see (plot)
> how each row of data (percentages) varies with income, making many small
> graphs in the same plot. For each row of data there will be one graph. I
> can manually delete the "No Answer" rows in Excel, if that is the best
> solution. I want the output to look like the sparklines in column "I" of
> attached Excel screenshot, with labelling of each graphs. This is similar
> to the attached "Example_plot". I thought this could be done with Lattice,
> or base-R, or ggplot easily, but this turning out to be more difficult than
> I had thought.
>
> On Mon, 3 Jul 2023 at 14:38, Anupam Tyagi  wrote:
>
>> Thanks Jim, thanks everyone. I was caught up with work and moving home,
>> so a delay in response. I tried running the code you provided and it is not
>> running well in my R-Studio setup. It is giving errors and not producing
>> plots. I don't yet understand all the code well yet, so I need to work on
>> it and then get back to you all. Sorry for not posting data from a R
>> dataframe. My data is still in Excel. I organized data in Excel almost
>> exactly (look wise) as the output from Stata log file (text) for a
>> "tabulate" command for a survey dataset. I don't yet understand a good way
>> to organize this data in R, so I cannot send it to you now. Let me do some
>> work on this, understand the R code you have given, and get back to you in
>> a few days. I have not been using R lately, but I think the graph I am
>> trying to make will be done better and easier in R than in Stata. Thank you
>> all for all your help. Let me do some work and get back to you.
>>
>>
>> On Fri, 30 Jun 2023 at 04:41, Jim Lemon  wrote:
>>
>>> Okay. Here is a modification that does four single line plots.
>>>
>>> at_df<-read.table(text=
>>>  "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current
>>> Bank_Savings Bank_NA
>>>  $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
>>>  $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
>>>  $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
>>>  $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
>>>  >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208
>>>  No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
>>>  header=TRUE,stringsAsFactors=FALSE)
>>> at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")]
>>> png("Income_pcts.png",height=700)
>>> par(mfrow=c(4,1))
>>> plot(at_df[,"Bank_Current"],
>>>  type="l",lwd=3,main="Bsnk_Current",
>>>  xlab="Income",ylab="%",xaxt="n")
>>> axis(1,at=1:5,labels=at_df$Income)
>>> plot(at_df[,"Bank_Savings"],
>>>  type="l",lwd=3,main="Bank_Sasvings",
>>>  xlab="Income",ylab="%",xaxt="n")
>>> axis(1,at=1:5,labels=at_df$Income)
>>> plot(at_df[,"MF_Equity"],
>>>  type="l",lwd=3,main="MF_Equity",
>>>  xlab="Income",ylab="%",xaxt="n")
>>> axis(1,at=1:5,labels=at_df$Income)
>>> plot(at_df[,"MF_Debt"],
>>>  type="l",lwd=3,main="MF_Debt",
>>>  xlab="Income",ylab="%",xaxt="n")
>>> axis(1,at=1:5,labels=at_df$Income)
>>> dev.off()
>>>
>>> Jim
>>>
>>> On Thu, Jun 29, 2023 at 1:49 PM Anupam Tyagi 
>>> wrote:
>>> >
>>> > Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you
>>> have
>>> > been well.
>>> >
>>> > Pikal, thanks. Your solution may be close to what I want. I did not
>>> know
>>> > that I was posting in HTML. I just copied the data from Excel and
>>> posted in
>>> > the email in Gmail. The data is still in Excel, because I have not yet
>>> > figured out what is a good way to organize it in R. I am posting it
>>> again
>>> > below as text. These are rows in Excel: 1,2,3,5,9 after MF are income
>>> > categories and No Answer category (9). Down the second column are
>>> > categories of MF and Bank AC. Rest of the columns are percentages.
>>> >
>>> > Jim, thanks for the graph. I am looking to plot only one line
>>> (category)
>>> > each in many small plots on the same page. I don't want to compare
>>> > different categories on the same graph as you do, but see how each
>>> category
>>> > varies by income, one category in each graph. Like Excel does with
>>> > Sparklines (Top menu: Insert, Sparklines, Lines). I have many
>>> categories
>>> > for many variables. I am only showing two MF and Bank AC.
>>> >
>>> > Income $10 $25 $40 $75 > $75 No Answer
>>> > MF 1 2 3 4 5 9
>>> > None 1 3.05 2.29 2.24 1.71 1.30 2.83
>>> > Equity 2 29.76 28.79 29.51 28.90 31.67 36.77
>>> > Debt 3 31.18 32.64 34.31 35.65 37.59 33.15
>>> > Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25
>>> > Bank AC
>>> > None 1 46.54 54.01 59.1 62.17 67.67 60.87
>>> > Current 2 24.75 24.4 25 24.61 24.02 21.09
>>> > Savings 3 25.4 18.7 29 11.48 7.103 13.46
>>> > No Answer 9 3.307 2.891 13.4 1.746 1.208 

Re: [R] Plotting factors in graph panel

2023-07-03 Thread Anupam Tyagi
Thanks Jim, thanks everyone. I was caught up with work and moving home, so
a delay in response. I tried running the code you provided and it is not
running well in my R-Studio setup. It is giving errors and not producing
plots. I don't yet understand all the code well yet, so I need to work on
it and then get back to you all. Sorry for not posting data from a R
dataframe. My data is still in Excel. I organized data in Excel almost
exactly (look wise) as the output from Stata log file (text) for a
"tabulate" command for a survey dataset. I don't yet understand a good way
to organize this data in R, so I cannot send it to you now. Let me do some
work on this, understand the R code you have given, and get back to you in
a few days. I have not been using R lately, but I think the graph I am
trying to make will be done better and easier in R than in Stata. Thank you
all for all your help. Let me do some work and get back to you.


On Fri, 30 Jun 2023 at 04:41, Jim Lemon  wrote:

> Okay. Here is a modification that does four single line plots.
>
> at_df<-read.table(text=
>  "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current
> Bank_Savings Bank_NA
>  $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
>  $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
>  $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
>  $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
>  >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208
>  No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
>  header=TRUE,stringsAsFactors=FALSE)
> at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")]
> png("Income_pcts.png",height=700)
> par(mfrow=c(4,1))
> plot(at_df[,"Bank_Current"],
>  type="l",lwd=3,main="Bsnk_Current",
>  xlab="Income",ylab="%",xaxt="n")
> axis(1,at=1:5,labels=at_df$Income)
> plot(at_df[,"Bank_Savings"],
>  type="l",lwd=3,main="Bank_Sasvings",
>  xlab="Income",ylab="%",xaxt="n")
> axis(1,at=1:5,labels=at_df$Income)
> plot(at_df[,"MF_Equity"],
>  type="l",lwd=3,main="MF_Equity",
>  xlab="Income",ylab="%",xaxt="n")
> axis(1,at=1:5,labels=at_df$Income)
> plot(at_df[,"MF_Debt"],
>  type="l",lwd=3,main="MF_Debt",
>  xlab="Income",ylab="%",xaxt="n")
> axis(1,at=1:5,labels=at_df$Income)
> dev.off()
>
> Jim
>
> On Thu, Jun 29, 2023 at 1:49 PM Anupam Tyagi  wrote:
> >
> > Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have
> > been well.
> >
> > Pikal, thanks. Your solution may be close to what I want. I did not know
> > that I was posting in HTML. I just copied the data from Excel and posted
> in
> > the email in Gmail. The data is still in Excel, because I have not yet
> > figured out what is a good way to organize it in R. I am posting it again
> > below as text. These are rows in Excel: 1,2,3,5,9 after MF are income
> > categories and No Answer category (9). Down the second column are
> > categories of MF and Bank AC. Rest of the columns are percentages.
> >
> > Jim, thanks for the graph. I am looking to plot only one line (category)
> > each in many small plots on the same page. I don't want to compare
> > different categories on the same graph as you do, but see how each
> category
> > varies by income, one category in each graph. Like Excel does with
> > Sparklines (Top menu: Insert, Sparklines, Lines). I have many categories
> > for many variables. I am only showing two MF and Bank AC.
> >
> > Income $10 $25 $40 $75 > $75 No Answer
> > MF 1 2 3 4 5 9
> > None 1 3.05 2.29 2.24 1.71 1.30 2.83
> > Equity 2 29.76 28.79 29.51 28.90 31.67 36.77
> > Debt 3 31.18 32.64 34.31 35.65 37.59 33.15
> > Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25
> > Bank AC
> > None 1 46.54 54.01 59.1 62.17 67.67 60.87
> > Current 2 24.75 24.4 25 24.61 24.02 21.09
> > Savings 3 25.4 18.7 29 11.48 7.103 13.46
> > No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577
> >
> >
> > On Wed, 28 Jun 2023 at 17:30, Jim Lemon  wrote:
> >
> > > Hi Anupam,
> > > Haven't heard from you in a long time. Perhaps you want something like
> > > this:
> > >
> > > at_df<-read.table(text=
> > >  "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current
> > > Bank_Savings Bank_NA
> > >  $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
> > >  $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
> > >  $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
> > >  $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
> > >  >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208
> > >  No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
> > >  header=TRUE,stringsAsFactors=FALSE)
> > > at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")]
> > > png("MF_Bank.png",height=600)
> > > par(mfrow=c(2,1))
> > > matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")],
> > >  type="l",col=1:4,lty=1:4,lwd=3,
> > >  main="Percentages by Income and MF type",
> > >  xlab="Income",ylab="Percentage of group",xaxt="n")
> > > axis(1,at=1:5,labels=at_df$Income)
> > > 

Re: [R] Plotting factors in graph panel

2023-06-29 Thread Jim Lemon
Okay. Here is a modification that does four single line plots.

at_df<-read.table(text=
 "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current
Bank_Savings Bank_NA
 $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
 $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
 $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
 $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
 >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208
 No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
 header=TRUE,stringsAsFactors=FALSE)
at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")]
png("Income_pcts.png",height=700)
par(mfrow=c(4,1))
plot(at_df[,"Bank_Current"],
 type="l",lwd=3,main="Bsnk_Current",
 xlab="Income",ylab="%",xaxt="n")
axis(1,at=1:5,labels=at_df$Income)
plot(at_df[,"Bank_Savings"],
 type="l",lwd=3,main="Bank_Sasvings",
 xlab="Income",ylab="%",xaxt="n")
axis(1,at=1:5,labels=at_df$Income)
plot(at_df[,"MF_Equity"],
 type="l",lwd=3,main="MF_Equity",
 xlab="Income",ylab="%",xaxt="n")
axis(1,at=1:5,labels=at_df$Income)
plot(at_df[,"MF_Debt"],
 type="l",lwd=3,main="MF_Debt",
 xlab="Income",ylab="%",xaxt="n")
axis(1,at=1:5,labels=at_df$Income)
dev.off()

Jim

On Thu, Jun 29, 2023 at 1:49 PM Anupam Tyagi  wrote:
>
> Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have
> been well.
>
> Pikal, thanks. Your solution may be close to what I want. I did not know
> that I was posting in HTML. I just copied the data from Excel and posted in
> the email in Gmail. The data is still in Excel, because I have not yet
> figured out what is a good way to organize it in R. I am posting it again
> below as text. These are rows in Excel: 1,2,3,5,9 after MF are income
> categories and No Answer category (9). Down the second column are
> categories of MF and Bank AC. Rest of the columns are percentages.
>
> Jim, thanks for the graph. I am looking to plot only one line (category)
> each in many small plots on the same page. I don't want to compare
> different categories on the same graph as you do, but see how each category
> varies by income, one category in each graph. Like Excel does with
> Sparklines (Top menu: Insert, Sparklines, Lines). I have many categories
> for many variables. I am only showing two MF and Bank AC.
>
> Income $10 $25 $40 $75 > $75 No Answer
> MF 1 2 3 4 5 9
> None 1 3.05 2.29 2.24 1.71 1.30 2.83
> Equity 2 29.76 28.79 29.51 28.90 31.67 36.77
> Debt 3 31.18 32.64 34.31 35.65 37.59 33.15
> Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25
> Bank AC
> None 1 46.54 54.01 59.1 62.17 67.67 60.87
> Current 2 24.75 24.4 25 24.61 24.02 21.09
> Savings 3 25.4 18.7 29 11.48 7.103 13.46
> No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577
>
>
> On Wed, 28 Jun 2023 at 17:30, Jim Lemon  wrote:
>
> > Hi Anupam,
> > Haven't heard from you in a long time. Perhaps you want something like
> > this:
> >
> > at_df<-read.table(text=
> >  "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current
> > Bank_Savings Bank_NA
> >  $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
> >  $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
> >  $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
> >  $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
> >  >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208
> >  No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
> >  header=TRUE,stringsAsFactors=FALSE)
> > at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")]
> > png("MF_Bank.png",height=600)
> > par(mfrow=c(2,1))
> > matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")],
> >  type="l",col=1:4,lty=1:4,lwd=3,
> >  main="Percentages by Income and MF type",
> >  xlab="Income",ylab="Percentage of group",xaxt="n")
> > axis(1,at=1:5,labels=at_df$Income)
> > legend(3,24,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid"),
> >  lty=1:4,lwd=3,col=1:4)
> > matplot(at_df[,c("Bank_None","Bank_Current","Bank_Savings")],
> >  type="l",col=1:3,lty=1:4,lwd=3,
> >  main="Percentages by Income and Bank type",
> >  xlab="Income",ylab="Percentage of group",xaxt="n")
> > axis(1,at=1:5,labels=at_df$Income)
> > legend(3,54,c("Bank_None","Bank_Current","Bank_Savings"),
> >  lty=1:4,lwd=3,col=1:3)
> > dev.off()
> >
> > Jim
> >
> > On Wed, Jun 28, 2023 at 6:33 PM Anupam Tyagi  wrote:
> > >
> > > Hello,
> > >
> > > I want to plot the following kind of data (percentage of respondents
> > from a
> > > survey) that varies by Income into many small *line* graphs in a panel of
> > > graphs. I want to omit "No Answer" categories. I want to see how each one
> > > of the categories (percentages), "None", " Equity", etc. varies by
> > Income.
> > > How can I do this? How to organize the data well and how to plot? I
> > thought
> > > Lattice may be a good package to plot this, but I don't know for sure. I
> > > prefer to do this in Base-R if possible, but I am open to ggplot. Any
> > ideas
> > > will be helpful.
> > >
> > > Income
> > > $10 $25 $40 $75 > $75 No Answer
> > > MF 1 2 3 4 5 9
> > 

Re: [R] Plotting factors in graph panel

2023-06-29 Thread John Kane
Anupa,

I think your  best bet with your data would be to tidy it up in Excel, read
it into  R using something like the readxl package and then supply some
sample data is the dput() function.

In the case of a large dataset something like dput(head(mydata, 100))
should supply the data we need. Just do dput(mydata) where *mydata* is your
data. Copy the output and paste it here.

On Thu, 29 Jun 2023 at 08:37, Ebert,Timothy Aaron  wrote:

> Reposting the data did not help. We do not like to guess, and doing so
> takes a great deal of time that is likely wasted.
> Rows are observations.
> Columns are variables.
> In Excel, the first row will be variable names and all subsequent rows
> will be observations.
>
> Income is the first variable. It has seven states: $10, $25, $40, $75,
> >$75, "No", "Answer"
> MF is the second variable. It has six values: 1, 2, 3, 4, 5, 9
> None is the third variable. It has seven values: 1, 3.05,  2.29, 2.24,
> 1.71, 1.30, 2.83
> Equity is the last variable with many states, both numeric and text. A
> computer will read it all as text.
>
> As written the data cannot be analyzed.
>
> Equity looks like it should be numeric. However, it has text values:
> "Debt", "Hybrid", Bank", "AC", "None", "Current", "Savings", "No", and
> "Answer"
>
> In looking at the data I try to find some organization where every
> variable has the same number of rows as every other variable. I fail with
> these data.
> I could combine "No" and "Answer" into one name "No Answer" to make it
> agree with MF, but then it does not work for None.
>
>
> Please rework the data in Excel so that we can properly interpret the
> content. If it is badly organized in Excel, moving it to R will not help.
> Below, I tried adding carriage returns and spaces to organize the data,
> but I have a column of numbers that are not identified. The values below
> $10 do not make much sense compared to other values.
>
> I am tired of guessing.
>
> Tim
>
> -Original Message-
> From: R-help  On Behalf Of Anupam Tyagi
> Sent: Wednesday, June 28, 2023 11:49 PM
> To: r-help@r-project.org
> Subject: Re: [R] Plotting factors in graph panel
>
> [External Email]
>
> Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have
> been well.
>
> Pikal, thanks. Your solution may be close to what I want. I did not know
> that I was posting in HTML. I just copied the data from Excel and posted in
> the email in Gmail. The data is still in Excel, because I have not yet
> figured out what is a good way to organize it in R. I am posting it again
> below as text. These are rows in Excel: 1,2,3,5,9 after MF are income
> categories and No Answer category (9). Down the second column are
> categories of MF and Bank AC. Rest of the columns are percentages.
>
> Jim, thanks for the graph. I am looking to plot only one line (category)
> each in many small plots on the same page. I don't want to compare
> different categories on the same graph as you do, but see how each category
> varies by income, one category in each graph. Like Excel does with
> Sparklines (Top menu: Insert, Sparklines, Lines). I have many categories
> for many variables. I am only showing two MF and Bank AC.
>
> Income$10 $25 $40  $75   > $75No Answer
> MF   1  2 3   4 5  9
> None   1   3.05 2.292.24 1.711.30
>  2.83
> Equity 229.76  28.79  29.51 28.90   31.6736.77
>
> Debt3  31.18  32.64  34.31  35.65  37.59 33.15
>
> Hybrid  4 36.00 36.27 33.94 33.74 29.44 27.25
>
> Bank AC None 1 46.54 54.01 59.1 62.17 67.67 60.87
>
> Current2 24.75 24.4 25 24.61 24.02 21.09
>
> Savings 3 25.4 18.7 29 11.48 7.103 13.46
>
> No Answer   9 3.307 2.891 13.4 1.746 1.208 4.577
>
>
> On Wed, 28 Jun 2023 at 17:30, Jim Lemon  wrote:
>
> > Hi Anupam,
> > Haven't heard from you in a long time. Perhaps you want something like
> > this:
> >
> > at_df<-read.table(text=
> >  "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current
> > Bank_Savings Bank_NA
> >  $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
> >  $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
> >  $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
> >  $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
> >  >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208  No_Answer 9
> > 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
> >  heade

Re: [R] Plotting factors in graph panel

2023-06-29 Thread Ebert,Timothy Aaron
Reposting the data did not help. We do not like to guess, and doing so takes a 
great deal of time that is likely wasted.
Rows are observations.
Columns are variables.
In Excel, the first row will be variable names and all subsequent rows will be 
observations.

Income is the first variable. It has seven states: $10, $25, $40, $75, >$75, 
"No", "Answer"
MF is the second variable. It has six values: 1, 2, 3, 4, 5, 9
None is the third variable. It has seven values: 1, 3.05,  2.29, 2.24, 1.71, 
1.30, 2.83
Equity is the last variable with many states, both numeric and text. A computer 
will read it all as text.

As written the data cannot be analyzed.

Equity looks like it should be numeric. However, it has text values: "Debt", 
"Hybrid", Bank", "AC", "None", "Current", "Savings", "No", and "Answer"

In looking at the data I try to find some organization where every variable has 
the same number of rows as every other variable. I fail with these data.
I could combine "No" and "Answer" into one name "No Answer" to make it agree 
with MF, but then it does not work for None.


Please rework the data in Excel so that we can properly interpret the content. 
If it is badly organized in Excel, moving it to R will not help.
Below, I tried adding carriage returns and spaces to organize the data, but I 
have a column of numbers that are not identified. The values below $10 do not 
make much sense compared to other values.

I am tired of guessing.

Tim

-----Original Message-
From: R-help  On Behalf Of Anupam Tyagi
Sent: Wednesday, June 28, 2023 11:49 PM
To: r-help@r-project.org
Subject: Re: [R] Plotting factors in graph panel

[External Email]

Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have been 
well.

Pikal, thanks. Your solution may be close to what I want. I did not know that I 
was posting in HTML. I just copied the data from Excel and posted in the email 
in Gmail. The data is still in Excel, because I have not yet figured out what 
is a good way to organize it in R. I am posting it again below as text. These 
are rows in Excel: 1,2,3,5,9 after MF are income categories and No Answer 
category (9). Down the second column are categories of MF and Bank AC. Rest of 
the columns are percentages.

Jim, thanks for the graph. I am looking to plot only one line (category) each 
in many small plots on the same page. I don't want to compare different 
categories on the same graph as you do, but see how each category varies by 
income, one category in each graph. Like Excel does with Sparklines (Top menu: 
Insert, Sparklines, Lines). I have many categories for many variables. I am 
only showing two MF and Bank AC.

Income$10 $25 $40  $75   > $75No Answer
MF   1  2 3   4 5  9
None   1   3.05 2.292.24 1.711.30   2.83
Equity 229.76  28.79  29.51 28.90   31.6736.77

Debt3  31.18  32.64  34.31  35.65  37.59 33.15

Hybrid  4 36.00 36.27 33.94 33.74 29.44 27.25

Bank AC None 1 46.54 54.01 59.1 62.17 67.67 60.87

Current2 24.75 24.4 25 24.61 24.02 21.09

Savings 3 25.4 18.7 29 11.48 7.103 13.46

No Answer   9 3.307 2.891 13.4 1.746 1.208 4.577


On Wed, 28 Jun 2023 at 17:30, Jim Lemon  wrote:

> Hi Anupam,
> Haven't heard from you in a long time. Perhaps you want something like
> this:
>
> at_df<-read.table(text=
>  "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current
> Bank_Savings Bank_NA
>  $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
>  $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
>  $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
>  $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
>  >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208  No_Answer 9
> 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
>  header=TRUE,stringsAsFactors=FALSE)
> at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")]
> png("MF_Bank.png",height=600)
> par(mfrow=c(2,1))
> matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")],
>  type="l",col=1:4,lty=1:4,lwd=3,
>  main="Percentages by Income and MF type",
> xlab="Income",ylab="Percentage of group",xaxt="n")
> axis(1,at=1:5,labels=at_df$Income)
> legend(3,24,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid"),
>  lty=1:4,lwd=3,col=1:4)
> matplot(at_df[,c("Bank_None","Bank_Current","Bank_Savings")],
>  type="l",col=1:3,lty=1:4,lwd=3,
>  main="Percentages by Income and Bank type",

Re: [R] Plotting factors in graph panel

2023-06-29 Thread PIKAL Petr
Hi Anupam

Using Jim's data

library(reshape2)
at_long <- melt(at_df)
at_long$innum <- as.numeric(as.factor(at_long$Income))
ggplot(at_long, aes(x=innum, y=value)) + geom_path() + facet_wrap(~variable, 
ncol=1)

is probably close to what you want. 

You need to fiddle with labels, facets variable names to fit your needs.
Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Anupam Tyagi
> Sent: Thursday, June 29, 2023 5:49 AM
> To: r-help@r-project.org
> Subject: Re: [R] Plotting factors in graph panel
> 
> Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have been
> well.
> 
> Pikal, thanks. Your solution may be close to what I want. I did not know that 
> I
> was posting in HTML. I just copied the data from Excel and posted in the email
> in Gmail. The data is still in Excel, because I have not yet figured out what 
> is a
> good way to organize it in R. I am posting it again below as text. These are
> rows in Excel: 1,2,3,5,9 after MF are income categories and No Answer
> category (9). Down the second column are categories of MF and Bank AC.
> Rest of the columns are percentages.
> 
> Jim, thanks for the graph. I am looking to plot only one line (category) each 
> in
> many small plots on the same page. I don't want to compare different
> categories on the same graph as you do, but see how each category varies by
> income, one category in each graph. Like Excel does with Sparklines (Top
> menu: Insert, Sparklines, Lines). I have many categories for many variables. I
> am only showing two MF and Bank AC.
> 
> Income $10 $25 $40 $75 > $75 No Answer
> MF 1 2 3 4 5 9
> None 1 3.05 2.29 2.24 1.71 1.30 2.83
> Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 Debt 3 31.18 32.64 34.31 35.65
> 37.59 33.15 Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 Bank AC None 1
> 46.54 54.01 59.1 62.17 67.67 60.87 Current 2 24.75 24.4 25 24.61 24.02 21.09
> Savings 3 25.4 18.7 29 11.48 7.103 13.46 No Answer 9 3.307 2.891 13.4 1.746
> 1.208 4.577
> 
> 
> On Wed, 28 Jun 2023 at 17:30, Jim Lemon  wrote:
> 
> > Hi Anupam,
> > Haven't heard from you in a long time. Perhaps you want something like
> > this:
> >
> > at_df<-read.table(text=
> >  "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None
> Bank_Current
> > Bank_Savings Bank_NA
> >  $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
> >  $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
> >  $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
> >  $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
> >  >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208  No_Answer 9
> > 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
> >  header=TRUE,stringsAsFactors=FALSE)
> > at_df<-
> at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")]
> > png("MF_Bank.png",height=600)
> > par(mfrow=c(2,1))
> > matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")],
> >  type="l",col=1:4,lty=1:4,lwd=3,
> >  main="Percentages by Income and MF type",
> > xlab="Income",ylab="Percentage of group",xaxt="n")
> > axis(1,at=1:5,labels=at_df$Income)
> > legend(3,24,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid"),
> >  lty=1:4,lwd=3,col=1:4)
> > matplot(at_df[,c("Bank_None","Bank_Current","Bank_Savings")],
> >  type="l",col=1:3,lty=1:4,lwd=3,
> >  main="Percentages by Income and Bank type",
> > xlab="Income",ylab="Percentage of group",xaxt="n")
> > axis(1,at=1:5,labels=at_df$Income)
> > legend(3,54,c("Bank_None","Bank_Current","Bank_Savings"),
> >  lty=1:4,lwd=3,col=1:3)
> > dev.off()
> >
> > Jim
> >
> > On Wed, Jun 28, 2023 at 6:33 PM Anupam Tyagi 
> wrote:
> > >
> > > Hello,
> > >
> > > I want to plot the following kind of data (percentage of respondents
> > from a
> > > survey) that varies by Income into many small *line* graphs in a
> > > panel of graphs. I want to omit "No Answer" categories. I want to
> > > see how each one of the categories (percentages), "None", " Equity",
> > > etc. varies by
> > Income.
> > > How can I do this? How to organize the data well and how to plot? I
> > thought
> > > Lattice may be a good package to plot this, but I don't know for
> > > sure. I prefer to do this in Base-R if possible, but I am open to
> > > ggplot. Any
> > ideas
> 

Re: [R] Plotting factors in graph panel

2023-06-28 Thread Anupam Tyagi
Thanks, Pikal and Jim. Yes, it has been a long time Jim. I hope you have
been well.

Pikal, thanks. Your solution may be close to what I want. I did not know
that I was posting in HTML. I just copied the data from Excel and posted in
the email in Gmail. The data is still in Excel, because I have not yet
figured out what is a good way to organize it in R. I am posting it again
below as text. These are rows in Excel: 1,2,3,5,9 after MF are income
categories and No Answer category (9). Down the second column are
categories of MF and Bank AC. Rest of the columns are percentages.

Jim, thanks for the graph. I am looking to plot only one line (category)
each in many small plots on the same page. I don't want to compare
different categories on the same graph as you do, but see how each category
varies by income, one category in each graph. Like Excel does with
Sparklines (Top menu: Insert, Sparklines, Lines). I have many categories
for many variables. I am only showing two MF and Bank AC.

Income $10 $25 $40 $75 > $75 No Answer
MF 1 2 3 4 5 9
None 1 3.05 2.29 2.24 1.71 1.30 2.83
Equity 2 29.76 28.79 29.51 28.90 31.67 36.77
Debt 3 31.18 32.64 34.31 35.65 37.59 33.15
Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25
Bank AC
None 1 46.54 54.01 59.1 62.17 67.67 60.87
Current 2 24.75 24.4 25 24.61 24.02 21.09
Savings 3 25.4 18.7 29 11.48 7.103 13.46
No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577


On Wed, 28 Jun 2023 at 17:30, Jim Lemon  wrote:

> Hi Anupam,
> Haven't heard from you in a long time. Perhaps you want something like
> this:
>
> at_df<-read.table(text=
>  "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current
> Bank_Savings Bank_NA
>  $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
>  $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
>  $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
>  $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
>  >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208
>  No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
>  header=TRUE,stringsAsFactors=FALSE)
> at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")]
> png("MF_Bank.png",height=600)
> par(mfrow=c(2,1))
> matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")],
>  type="l",col=1:4,lty=1:4,lwd=3,
>  main="Percentages by Income and MF type",
>  xlab="Income",ylab="Percentage of group",xaxt="n")
> axis(1,at=1:5,labels=at_df$Income)
> legend(3,24,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid"),
>  lty=1:4,lwd=3,col=1:4)
> matplot(at_df[,c("Bank_None","Bank_Current","Bank_Savings")],
>  type="l",col=1:3,lty=1:4,lwd=3,
>  main="Percentages by Income and Bank type",
>  xlab="Income",ylab="Percentage of group",xaxt="n")
> axis(1,at=1:5,labels=at_df$Income)
> legend(3,54,c("Bank_None","Bank_Current","Bank_Savings"),
>  lty=1:4,lwd=3,col=1:3)
> dev.off()
>
> Jim
>
> On Wed, Jun 28, 2023 at 6:33 PM Anupam Tyagi  wrote:
> >
> > Hello,
> >
> > I want to plot the following kind of data (percentage of respondents
> from a
> > survey) that varies by Income into many small *line* graphs in a panel of
> > graphs. I want to omit "No Answer" categories. I want to see how each one
> > of the categories (percentages), "None", " Equity", etc. varies by
> Income.
> > How can I do this? How to organize the data well and how to plot? I
> thought
> > Lattice may be a good package to plot this, but I don't know for sure. I
> > prefer to do this in Base-R if possible, but I am open to ggplot. Any
> ideas
> > will be helpful.
> >
> > Income
> > $10 $25 $40 $75 > $75 No Answer
> > MF 1 2 3 4 5 9
> > None 1 3.05 2.29 2.24 1.71 1.30 2.83
> > Equity 2 29.76 28.79 29.51 28.90 31.67 36.77
> > Debt 3 31.18 32.64 34.31 35.65 37.59 33.15
> > Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25
> > Bank AC
> > None 1 46.54 54.01 59.1 62.17 67.67 60.87
> > Current 2 24.75 24.4 25 24.61 24.02 21.09
> > Savings 3 25.4 18.7 29 11.48 7.103 13.46
> > No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577
> >
> > Thanks.
> > --
> > Anupam.
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@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.
>


-- 
Anupam.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Plotting factors in graph panel

2023-06-28 Thread Jim Lemon
Hi Anupam,
Haven't heard from you in a long time. Perhaps you want something like this:

at_df<-read.table(text=
 "Income MF MF_None MF_Equity MF_Debt MF_Hybrid Bank_None Bank_Current
Bank_Savings Bank_NA
 $10 1 3.05 29.76 31.18 36.0 46.54 24.75 25.4 3.307
 $25 2 2.29 28.79 32.64 36.27 54.01 24.4 18.7 2.891
 $40 3 2.24 29.51 34.31 33.94 59.1 25.0 29 13.4
 $75 4 1.71 28.90 35.65 33.74 62.17 24.61 11.48 1.746
 >$75 5 1.30 31.67 37.59 29.44 67.67 24.02 7.103 1.208
 No_Answer 9 2.83 36.77 33.15 27.25 60.87 21.09 13.46 4.577",
 header=TRUE,stringsAsFactors=FALSE)
at_df<-at_df[at_df$Income!="No_Answer",which(names(at_df)!="Bank_NA")]
png("MF_Bank.png",height=600)
par(mfrow=c(2,1))
matplot(at_df[,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid")],
 type="l",col=1:4,lty=1:4,lwd=3,
 main="Percentages by Income and MF type",
 xlab="Income",ylab="Percentage of group",xaxt="n")
axis(1,at=1:5,labels=at_df$Income)
legend(3,24,c("MF_None","MF_Equity","MF_Debt","MF_Hybrid"),
 lty=1:4,lwd=3,col=1:4)
matplot(at_df[,c("Bank_None","Bank_Current","Bank_Savings")],
 type="l",col=1:3,lty=1:4,lwd=3,
 main="Percentages by Income and Bank type",
 xlab="Income",ylab="Percentage of group",xaxt="n")
axis(1,at=1:5,labels=at_df$Income)
legend(3,54,c("Bank_None","Bank_Current","Bank_Savings"),
 lty=1:4,lwd=3,col=1:3)
dev.off()

Jim

On Wed, Jun 28, 2023 at 6:33 PM Anupam Tyagi  wrote:
>
> Hello,
>
> I want to plot the following kind of data (percentage of respondents from a
> survey) that varies by Income into many small *line* graphs in a panel of
> graphs. I want to omit "No Answer" categories. I want to see how each one
> of the categories (percentages), "None", " Equity", etc. varies by Income.
> How can I do this? How to organize the data well and how to plot? I thought
> Lattice may be a good package to plot this, but I don't know for sure. I
> prefer to do this in Base-R if possible, but I am open to ggplot. Any ideas
> will be helpful.
>
> Income
> $10 $25 $40 $75 > $75 No Answer
> MF 1 2 3 4 5 9
> None 1 3.05 2.29 2.24 1.71 1.30 2.83
> Equity 2 29.76 28.79 29.51 28.90 31.67 36.77
> Debt 3 31.18 32.64 34.31 35.65 37.59 33.15
> Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25
> Bank AC
> None 1 46.54 54.01 59.1 62.17 67.67 60.87
> Current 2 24.75 24.4 25 24.61 24.02 21.09
> Savings 3 25.4 18.7 29 11.48 7.103 13.46
> No Answer 9 3.307 2.891 13.4 1.746 1.208 4.577
>
> Thanks.
> --
> Anupam.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@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.
__
R-help@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.


Re: [R] Plotting factors in graph panel

2023-06-28 Thread PIKAL Petr
Hi

You probably can use any package including base R for such plots.

1. Posting in HTML scrambles your date so they are barely readable.
2. Use dput(head(yourdata, 20)) and copy the output to your mail to show how
your data look like. Although it seems to be not readable, R will consumes
it freely.
3. If I understand correctly you should have an Income column, Percentage
column and Category column. If this is the case

ggplot(yourdata, aes(x=Income, y=Percentage)) + geom_line() +
facet_grid(~Category) 

should give you what you want. But without data it is hard to say.

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Anupam Tyagi
> Sent: Wednesday, June 28, 2023 10:34 AM
> To: R-help@r-project.org
> Subject: [R] Plotting factors in graph panel
> 
> Hello,
> 
> I want to plot the following kind of data (percentage of respondents from
a
> survey) that varies by Income into many small *line* graphs in a panel of
> graphs. I want to omit "No Answer" categories. I want to see how each one
of
> the categories (percentages), "None", " Equity", etc. varies by Income.
> How can I do this? How to organize the data well and how to plot? I
thought
> Lattice may be a good package to plot this, but I don't know for sure. I
prefer
> to do this in Base-R if possible, but I am open to ggplot. Any ideas will
be
> helpful.
> 
> Income
> $10 $25 $40 $75 > $75 No Answer
> MF 1 2 3 4 5 9
> None 1 3.05 2.29 2.24 1.71 1.30 2.83
> Equity 2 29.76 28.79 29.51 28.90 31.67 36.77 Debt 3 31.18 32.64 34.31
35.65
> 37.59 33.15 Hybrid 4 36.00 36.27 33.94 33.74 29.44 27.25 Bank AC None 1
> 46.54 54.01 59.1 62.17 67.67 60.87 Current 2 24.75 24.4 25 24.61 24.02
21.09
> Savings 3 25.4 18.7 29 11.48 7.103 13.46 No Answer 9 3.307 2.891 13.4
1.746
> 1.208 4.577
> 
> Thanks.
> --
> Anupam.
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@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.
__
R-help@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.