limit bar graph output

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

limit bar graph output

reichmaj
R-Help Forum

I'm using the following code to reorder (from highest to lowest) my miRNA
counts.  But there are 500 plus and I only need the first (say) 15-20.  How
do I limit ggplot to only the first 20 miRNA counts

ggplot(data = corr.m, aes(x = reorder(miRNA, -value), y = value, fill =
variable)) +
  geom_bar(stat = "identity")

Jeff

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: limit bar graph output

Bert Gunter-2
If I understand correctly, just subset your sorted data.

e.g. :

x <- runif(50)
##  50 unsorted values

sort(x, dec = TRUE)[1:10]
## the 10 biggest


-- Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Oct 14, 2018 at 7:13 PM Jeff Reichman <[hidden email]>
wrote:

> R-Help Forum
>
> I'm using the following code to reorder (from highest to lowest) my miRNA
> counts.  But there are 500 plus and I only need the first (say) 15-20.  How
> do I limit ggplot to only the first 20 miRNA counts
>
> ggplot(data = corr.m, aes(x = reorder(miRNA, -value), y = value, fill =
> variable)) +
>   geom_bar(stat = "identity")
>
> Jeff
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: limit bar graph output

Jeff Newmiller
A reproducible example would help here (you cannot assume we know what type "miRNA" is) but guessing from the use of "reorder" I suspect it is a factor. In which case after you subset you will need to use the droplevels function to remove the unused levels, and then plot that prepared data.

On October 14, 2018 8:51:29 PM PDT, Bert Gunter <[hidden email]> wrote:

>If I understand correctly, just subset your sorted data.
>
>e.g. :
>
>x <- runif(50)
>##  50 unsorted values
>
>sort(x, dec = TRUE)[1:10]
>## the 10 biggest
>
>
>-- Bert
>
>
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and
>sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Sun, Oct 14, 2018 at 7:13 PM Jeff Reichman <[hidden email]>
>wrote:
>
>> R-Help Forum
>>
>> I'm using the following code to reorder (from highest to lowest) my
>miRNA
>> counts.  But there are 500 plus and I only need the first (say)
>15-20.  How
>> do I limit ggplot to only the first 20 miRNA counts
>>
>> ggplot(data = corr.m, aes(x = reorder(miRNA, -value), y = value, fill
>=
>> variable)) +
>>   geom_bar(stat = "identity")
>>
>> Jeff
>>
>> ______________________________________________
>> [hidden email] 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]]
>
>______________________________________________
>[hidden email] 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.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: limit bar graph output

reichmaj
In reply to this post by Bert Gunter-2
Bert

Jeff

 

I just resorted and took the top 30 and then reordered again in the geom_bar function – below

 

ggplot(data=st.cnt)+

  geom_bar(aes(x=reorder(CourseName, -n), y=n),fill = "dark blue", stat="identity")+

  theme(axis.text.x = element_text(angle = 60, hjust = 1))

 

Jeff

 

From: Bert Gunter <[hidden email]>
Sent: Sunday, October 14, 2018 10:51 PM
To: [hidden email]
Cc: R-help <[hidden email]>
Subject: Re: [R] limit bar graph output

 

If I understand correctly, just subset your sorted data.

 

e.g. :

 

x <- runif(50)

##  50 unsorted values

 

sort(x, dec = TRUE)[1:10]  

## the 10 biggest

 

 

-- Bert

 

 




Bert Gunter

"The trouble with having an open mind is that people keep coming along and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

 

 

On Sun, Oct 14, 2018 at 7:13 PM Jeff Reichman <[hidden email] <mailto:[hidden email]> > wrote:

R-Help Forum

I'm using the following code to reorder (from highest to lowest) my miRNA
counts.  But there are 500 plus and I only need the first (say) 15-20.  How
do I limit ggplot to only the first 20 miRNA counts

ggplot(data = corr.m, aes(x = reorder(miRNA, -value), y = value, fill =
variable)) +
  geom_bar(stat = "identity")

Jeff

______________________________________________
[hidden email] <mailto:[hidden email]>  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]]

______________________________________________
[hidden email] 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.