Displaying 20 results from an estimated 4000 matches similar to: "Change the legend order by order function"
2018 May 22
3
legend order in ggplot2
Hi,
I'd like to graph three lines on ggplot2 and I intend the lines to be
"solid", "dashed", and "dotted". The legend names are "name_b", "name_a",
"name_c". I'd like to legend to present in the order: the "name_b" at the
top, and "name_c" at the bottom.
As a consequence, the legend is indeed in the order:
2018 May 23
0
Change the legend order by order function
There are two key concepts you seem to be unaware of regarding ggplot: 1) you really need to put your data in long format to work with multiple curves, and 2) the column containing the names of the curves should be a factor with levels in the order you wish them to be presented in the legend (bottom to top). I am not in a position at the moment to give you a full reprex, but Google can probably
2018 May 22
0
legend order in ggplot2
Hi
Your approach seems to me rather complicated. I would reshape data before plotting and maybe also change order of levels in resulting variable factor
library(reshape2)
dfm<-melt(df)
dfm$variable<-factor(dfm$variable, levels=levels(dfm$variable)[c(2,1,3,4)])
p2<-ggplot(dfm, aes(x=rep(1:2,4), y=value))
p2+geom_line(aes(linetype=variable))+
2018 May 23
1
legend order in ggplot2
Hi,
I ran your code, but the results were not as expected. After I ran the
code by "source", it return
No id variables; using all as measure variables
> p2
and no line or legend is on the graph (as attached)
Am I doing anything wrong?
John
library(ggplot2)
library(reshape2)
dfm<-melt(df)
dfm$variable<-factor(dfm$variable, levels=levels(dfm$variable)[c(2,1,3,4)])
2009 Apr 09
2
how to automatically select certain columns using for loop in dataframe
Hi,
I am trying to display / print certain columns in my data frame that share
certain condition (for example, part of the column name). I am using for
loop, as follow:
# below is the sample data structure
all.data <- data.frame( NUM_A = 1:5, NAME_A = c("Andy", "Andrew", "Angus",
"Alex", "Argo"),
NUM_B = 1:5, NAME_B =
2017 Oct 12
2
dual y-axis for ggplot
Hi,
To my knowledge, an excellent of ggplot with a second y-axis is
https://rpubs.com/MarkusLoew/226759
In this example, the author uses two colors for the two lines, but the
line shapes are the same -- both are solid. Could each line have its own
color as well as its own shape? For example, can I make the red line with
the linetype "twodash", while the blue line with the
2024 Jul 18
1
ggplot two-factor legend
?s 17:43 de 18/07/2024, Rui Barradas escreveu:
> ?s 16:27 de 18/07/2024, SIBYLLE ST?CKLI via R-help escreveu:
>> Hi
>>
>> I am using ggplot to visualise y for a two-factorial group (Bio: 0 and
>> 1) x
>> = 6 years. I was able to adapt the colour of the lines (green and red)
>> and
>> the linetype (solid and dashed).
>> Challenge: my code
2017 Oct 12
1
dual y-axis for ggplot
Hi John,
You can try the following:
override.linetype=c("twodash","solid")
p <- ggplot(obs, aes(x = Timestamp))
p <- p + geom_line(aes(y = air_temp, colour = "Temperature", linetype
="Temperature"))
p <- p + geom_line(aes(y = rel_hum/5, colour = "Humidity",
linetype="Humidity"))
p <- p +
2017 Oct 12
0
dual y-axis for ggplot
Sorry let me clarify.
If I modify the line
p <- p + geom_line(aes(y = air_temp, colour = "Temperature"))
by
p <- p + geom_line(aes(y = air_temp, colour = "Temperature", linetype
="Temperature"))
and
p <- p + geom_line(aes(y = rel_hum/5, colour = "Humidity"))
by
p <- p + geom_line(aes(y = rel_hum/5, colour = "Humidity",
2024 Jul 18
1
ggplot two-factor legend
?s 16:27 de 18/07/2024, SIBYLLE ST?CKLI via R-help escreveu:
> Hi
>
> I am using ggplot to visualise y for a two-factorial group (Bio: 0 and 1) x
> = 6 years. I was able to adapt the colour of the lines (green and red) and
> the linetype (solid and dashed).
> Challenge: my code produces now two legends. One with the colors for the
> group and one with the linetype for the
2013 Feb 01
2
Change default order of colors & line types
Dear R users,
I'd like to change the default order of colors & line types.
Especially I am using ggplot2 and using color Set1.
In Set1, the default color order is red, blue, green, violet,.. ect.
However, I want to put red in fourth (not first).
Likewise, I want to change the order of default linetype. I want to
put "solid" line in fourth.
How can I do thses?
R code to draw the
2009 Feb 18
1
lineplot in ggplot2 with different colour and linetype
Hi list,
I would like to use ggplot2 in creating a line plot with 4 lines (groups), 2
of which I want in colour and the remaining two as dotted lines.
### R code ###
library(ggplot2)
### create data ####
vals <- rnorm(400)
div<- c(rep("A",100),rep("B",100),rep("C",100),rep("D",100))
n<- rep(1:100,4)
df<- data.frame(div=
2016 Apr 09
1
Run script R
hi all ,?
i have an problem in script R . But when I execute the script R I face this error . can you help me please ???error:-----------------------------------------
Error in FUN(X[[i]], ...) :?? Theme element 'text' has NULL property: margin, debugIn addition: Warning messages:1: Removed 361 rows containing non-finite values (stat_smooth).?2: Removed 361 rows containing missing values
2012 Oct 22
1
how to group smooth line by two groups?
Hello, I have the following sample dataset.
sex <- as.factor(c(rep(0,12),rep(1,12)))
char <-
2024 Jul 18
2
ggplot two-factor legend
Hi
I am using ggplot to visualise y for a two-factorial group (Bio: 0 and 1) x
= 6 years. I was able to adapt the colour of the lines (green and red) and
the linetype (solid and dashed).
Challenge: my code produces now two legends. One with the colors for the
group and one with the linetype for the group. Does somebody have a hint how
to adapt the code to produce one legend? Group 0 = red and
2018 Jul 18
2
Legendas en una gráfica de ggplot2
Buenas tardes, estoy haciendo una gráfica de múltiples lineas pero no he
podido generar las legendas. Alguno de ustedes me podría colaborar.
library(ggplot2)
#### Con b=-2
t=seq (-4, 4, by=0.01)
l=exp(t+2)/(1+(exp(t+2)))
##con b igual a -1
t=seq (-4, 4, by=0.01)
o=exp(t+1)/(1+(exp(t+1)))
### Con b igual a 0.7
t=seq (-4, 4, by=0.01)
i=exp(t-0.7)/(1+(exp(t-0.7)))
### Con b igual a 2
t=seq
2008 Mar 25
1
Combining several mappings in ggplot2
Hello,
I want to be able to make a plot that has several series with
different color and linetype.
Online documentation suggest that this is possible, but I haven't found how:
"We can also create redundant mappings, mapping the same variable to
multiple aesthetics. This is most useful when producing a graphic for
both colour and black and white display."
Here's what I have to
2018 Jul 18
2
Legendas en una gráfica de ggplot2
¡Gracias! Espectacular. Me ha servido mucho.
El mié., 18 de jul. de 2018 1:15 PM, Víctor Granda García <
victorgrandagarcia en gmail.com> escribió:
> Hola Sebastián.
>
> Entiendo que tratas de que aparezca una leyenda con el tipo de curva
> (l,o,u,i). Si quieres aprovechar las ventajas de ggplot (como las leyendas
> automáticas) normalmente tienes que asignar linetype a una
2023 Aug 12
1
geom_smooth
?s 05:17 de 12/08/2023, Thomas Subia via R-help escreveu:
> Colleagues,
>
> Here is my reproducible code for a graph using geom_smooth
> set.seed(55)
> scatter_data <- tibble(x_var = runif(100, min = 0, max = 25)
> ?????????????????????? ,y_var = log2(x_var) + rnorm(100))
>
> library(ggplot2)
> library(cowplot)
>
> ggplot(scatter_data,aes(x=x_var,y=y_var))+
2024 Jul 18
1
ggplot two-factor legend
If I follow your question, you want redundant aesthetics. Ggplot normally notices correlated aesthetic mapping variables and merges the legends, so the most likely answer is that your data are not fully correlated in all rows. I have also seen this where data are drawn from different dataframes for different layers since it is hard to merge factors, but I don't see that here.
You are using