Reorder does not work after adding second geom_points

Reorder does not work after adding second geom_points

Content Index :

Reorder does not work after adding second geom_points
Tag : r , By : Eric
Date : November 21 2020, 03:00 PM

fixed the issue. Will look into that further Several suggestions for consideration...
1: Wrangle your data frame before feeding it into ggplot(). Since trait is a categorical variable, you can specify its levels as a factor explicitly.

g2 <- GEE %>%
  mutate(trait = factor(trait, levels = trait[order(beta[analysis == "group1"])]))

> levels(g2$trait)
[1] "trait3" "trait5" "trait4" "trait2" "trait1"
ggplot(GEE, aes(x = beta, y = analysis, label = trait)) + geom_label()
ggplot(g2, aes(y = beta, x = trait, group = analysis, color = analysis,
               ymin = beta - 2*se, ymax = beta + 2*se)) + 
  geom_point(aes(alpha = signif),   # hide non-significant points while using the same dataset
             color = "red") +       # override 'color = analysis' in ggplot()
  geom_point() +
  geom_errorbar() +
pd <- position_dodge(0.9)

ggplot(g2, aes(y = beta, x = trait, group = analysis, color = analysis,
               ymin = beta - 2*se, ymax = beta + 2*se)) + 
  geom_point(aes(alpha = signif), 
             color = "red", shape = "*", size = 12, show.legend = F,
             position = pd) +
  geom_point(position = pd) +
  geom_errorbar(width=.2, position = pd) +
  scale_alpha_identity() +
  theme_light() +
GEE <- read.csv(
  text = 

> levels(GEE$trait) # default order is 1-2-3-4-5
[1] "trait1" "trait2" "trait3" "trait4" "trait5"

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Two geom_points add a legend

Tag : r , By : Helpful Dude
Date : March 29 2020, 07:55 AM
wish help you to fix your issue If you rename your columns of the original data frame and then melt it into long format withreshape2::melt, it's much easier to handle in ggplot2. By specifying the color and shape aesthetics in the ggplot command, and specifying the scales for the colors and shapes manually, the legend will appear.

names(arbuthnot) <- c("Year", "Men", "Women")

arbuthnot.melt <- melt(arbuthnot, id.vars = 'Year', variable.name = 'Sex', 
    value.name = 'Rate')

ggplot(arbuthnot.melt, aes(x = Year, y = Rate, shape = Sex, color = Sex))+
geom_point() + scale_color_manual(values = c("Women" = '#ff00ff','Men' = '#3399ff')) + 
scale_shape_manual(values = c('Women' = 17, 'Men' = 16))

Label geom_points, but not all of them

Tag : r , By : Kbotei
Date : March 29 2020, 07:55 AM
seems to work fine Since all values all present in werte, you can remove all instances of werte$ and xy$.
Second, you use two aes inside geom_text. Put all into one aes and it will work:
p <- ggplot() + 
  coord_fixed() +
  theme_bw() +
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank()) +
  scale_size_area(max_size = 20) +
  scale_x_continuous("<= Links - Rechts =>") +
  scale_y_continuous("<= Konservativ - Liberal =>") +
    mapping=aes(x=(x + abs(X_Mini) ) * 150 / (X_Maxi-X_Mini), 
                y=(y + abs(Y_Mini) ) * 150 / (Y_Maxi-Y_Mini),
                colour = kern_uml,
                alpha = 1/100 ), 
    scale_size_area(max_size = 30)
  ) +
  geom_text(data=subset(werte, avg_gult > 1000),
            aes(x=(x + abs(X_Mini) ) * 150 / (X_Maxi-X_Mini),
                y=(y + abs(Y_Mini) ) * 150  / (Y_Maxi-Y_Mini),

Offsetting two geom_points of the same category

Tag : r , By : user185283
Date : March 29 2020, 07:55 AM
I hope this helps . Convert your data to "long" format and you can then map Used and Available to a color aesthetic. This makes it easier to distinguish them, reduces the amount of code needed, and makes it easy to dodge them (using position_dodge()) so they don't overlap:

comp.m = melt(comp, id.var="Habitat")
comp.m = data.frame(comp.m[1:10,], err=comp.m[11:20,3])

pd = position_dodge(0.5)

ggplot(comp.m) +
  geom_point(aes(Habitat, value, color=variable), position=pd) +
  geom_errorbar(aes(Habitat, ymin=value - err, ymax=value + err,
                    color=variable), width=0.3, position=pd) +
  theme_classic() +

how do you make geom_points transparent

Tag : r , By : Zinovate
Date : March 29 2020, 07:55 AM
should help you out If you are trying to not plot your point, it is probably best to just subset the data in the geom_point. You could try changing your geom_point to:
geom_point(data = dat[!(dat$group2==0),], aes(x = label, y = group2, 
           color = color12, size = sizze, alpha = alpha))

selective jitter of geom_points

Tag : r , By : Jesse
Date : March 29 2020, 07:55 AM
will help you We can use duplicated or any similar function to detect the overlap, then we can use R indexing with jitter to apply jitter selectively.
I wrote it as a function:
selective_jitter <- function(x, # x = x co-ordinate
                             y, # y = y co-ordinate 
                             g  # g = group
  x <- as.numeric(x)
  y <- as.numeric(y)
  a <- cbind(x, y)
  a[duplicated(a)] <- jitter(a[duplicated(a)], amount = .15) # amount could be made a parameter

  final <- cbind(a, g)

data <- as.data.frame(selective_jitter(data$x, data$y, data$type))

ggplot() + geom_point(data = data, aes(x=x,y=y, color = g, fill = type), size = 2, shape = 25)
Related Posts Related QUESTIONS :
  • how to multiply each row with a scaler in corresponding column?
  • R is not recognizing levels of a factor as the same. Is there a way to do this?
  • Calculating mean of replicate experiment result values in a column based on multiple columns using R
  • Best method to extract the first instance of a string between specified keywords using data.table
  • ignore optional combination of alphanumeric characters in str_extract
  • Why tracemem shows two copies when modification occurs inside function body?
  • Can't use mppm on multitype point patterns
  • How to move selected matrix rows to top of matrix based on a selection vector of row names
  • Combining expressions with a common operator
  • Passing string through multiple filters for matching
  • Convert two columns in R to rows of unique occurrence
  • How to create a dataframe using a function based on user-input?
  • How to access the visited vertices in a given shortest path using R igraph
  • Differences in Unicode character output with print()
  • Extracting Function or Objects from a String and then Piping Them with Magrittr/Dplyr
  • renderUI not evaluated until it is rendered
  • Find the maximum absolute value by row in an R data frame
  • Extracting data from irregular lists using purrr:map()
  • transforming data based on range of column in r
  • Identify and subset rows with some similar information
  • converting character from mongolite to timestamp in R
  • Create list from two vectors with every combo of each
  • Error in running a spread because of unique 'key combinations'; combining rows of data
  • visualize numerical strings as a matrixed heatmap
  • how to make a blocked matrix?
  • How to summarize with two functions using with dplyr
  • Dataframe is no longer the same after being saved to Excel and read back in
  • Create duplicate rows using based on availability of data
  • Keep empty groups when grouping with data.table in R
  • Grouping of Event Time Data based on multiple, iterative conditions
  • Formatting Numbers in Flextable for Specific Columns
  • How to store results from for-loop into a dataframe
  • How to select the values in my dataframe which has logical operator "<" (less than), divide them by two, an
  • Rowwise extract data between two strings
  • Convert a string separate by . and +
  • stacking function for values in R
  • dplyr coerces characters to factors
  • How do I use spread and group_by on a single row dataset
  • Replacing values in one matrix with values from another
  • Aggregate data and exclude duplicates in one column
  • Perform an R data.table binary search with OR select
  • How can I include a function in the Standard Deviation parameter of pnorm
  • How to get a tidy excel output of P values from R
  • Rotate boxplot legend (R, ggplot2)
  • dplyr::n() returns “Error: Error: n() should only be called in a data context ”
  • Extract fix columns and one variable column from a list of df´s in R
  • A function that can translate DNA sequence to binary code
  • I want to extract 365 netcdf files using loop
  • rvest vs RSelenium results for text extracting
  • Converting wide data to tall data
  • How to remove vertical white lines when using ggsave in R?
  • R-Shiny error: "renderDataTable" and "server=FALSE"
  • Read csv file with selected rows using data.table's fread
  • how to resolve an error like non numeric argument to binary argument?
  • If value exists in environment
  • R get one value according to some rules in each group
  • Use any apply method to find difference between max and min score for each students
  • subsetting a dataframe by existing object
  • Parsing time formats in R
  • How to train a multiple linear regression model to find the best combination of variables?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com