logo
down
shadow

What units are the 'width = ' in geom_bar(aes = ) and position_dodge(width = ) rendered in?


What units are the 'width = ' in geom_bar(aes = ) and position_dodge(width = ) rendered in?

By : richu
Date : November 22 2020, 02:59 PM
will be helpful for those in need The width argument in position_dodge() is specifying the distance between the leftmost edge of the left bar and the rightmost edge of the right bar. With a dodge width of 0.8, the distance between your start point of x = 3 for your x3 category and the edge of either bar is 0.4 (+0.4 on the right and -0.4 on the left) Half of 0.4 (i.e. 0.2) will bring you to midpoint of the bar (again +0.2 on the right and -0.2 on the left). This is true irrespective of the bar width.
Here's an example where I've drawn an H on the right bar in cat3. The y-units line up with those on the y-axis.
code :
ggplot(data,aes(y = x1, x = x2)) + 
    geom_bar(stat = 'identity',
             aes(fill = x3, width = 0.5), 
             position = position_dodge(width = 0.8))+
    geom_text(aes(x = 3.2, y = 25, label = "H"), size = 10)


Share : facebook icon twitter icon
Why is line width in CoreGraphics on retina display rendered half width?

Why is line width in CoreGraphics on retina display rendered half width?


By : Chaitanya Purandare
Date : March 29 2020, 07:55 AM
it should still fix some issue My fault. 99% of my own bugs I solve on my own just after I post publicly about it.
The drawing code includes CGContextClip after constructing and copying a path. After that, a fill may be applied, gradient or otherwise, then the line drawn, so everything is nice and tidy. I was focusing on the math and specific drawing code, and did not notice the clipping line, but that would effectively halve the stroke width. Normally I catch logic bugs like this immediately, but because it was posted to SO, it's appropriate the answer is here too.
sizing a width by VW units while assuring a minimum width

sizing a width by VW units while assuring a minimum width


By : Tahuru
Date : March 29 2020, 07:55 AM
may help you . How can I size a DIV with a vw units on the upper size BUT assure a minimum width of at least 100px? , The original code worked fine:
code :
.container {
    min-width:1000px;
    width: 85vw;
}
CKEditor Table Width and Column Width Units

CKEditor Table Width and Column Width Units


By : mickreal
Date : March 29 2020, 07:55 AM
it helps some times There does not appear to be a configuration setting to change this behavior, and editing the plugin itself is probably a bit of a headache.
You could simply give your table a percentage width and leave the rest as is. Most modern browsers will treat/resize the cells in proportion. You could force this with jquery, or even with a simple CSS declaration. For example: $("table").width("100%");, or table { width: 100% !important; }.
code :
var tableWidth = $("table").width();
$("table tr").children().each(function( index ) {
    $(this).width(Math.round(100 * $(this).width() / tableWidth)+"%");
});
$("table").width("100%");

var tableWidth = $("table").width();
$("table tr").children().each(function( index ) {
    $(this).width(Math.round(100 * $(this).width() / tableWidth)+"%");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="1" cellpadding="1" cellspacing="1" style="width:1340px">
    <thead>
        <tr>
            <th scope="col" style="width:386px">1</th>
            <th scope="col" style="width:953px">
            <p>2</p>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td style="width:386px">3</td>
            <td style="width:953px">4</td>
        </tr>
    </tbody>
</table>
What is the width argument in position_dodge?

What is the width argument in position_dodge?


By : yetanotherdave
Date : March 29 2020, 07:55 AM
Does that help I will first give very brief answers to your three main questions. Then I walk through several examples to illustrate the answers more thoroughly.
Whose width does it specify?
code :
# some toy data
df <- data.frame(x = 1,
                 y = 1,
                 grp = c("A", "B"))

p <- ggplot(data = df, aes(x = x, y = y, fill = grp)) + theme_minimal()
p + geom_bar(stat = "identity",
             position = "dodge")
           # which is the same as:
           # position = position_dodge(width = NULL))
resolution(df$x)
# [1] 1
p2 <- p +
  geom_bar(stat = "identity",
           position = "stack")
ggplot_build(p2)$data[[1]]

#      fill x y label PANEL group ymin ymax xmin xmax colour size linetype alpha
# 1 #F8766D 1 1     A     1     1    0    1 0.55 1.45     NA  0.5        1    NA
# 2 #00BFC4 1 2     B     1     2    1    2 0.55 1.45     NA  0.5        1    NA
p +
  geom_bar(stat = "identity", width = 1, position = position_dodge(width = 0.9), alpha = 0.8)
p
p +
  geom_bar(stat = "identity", width = 1, position = "dodge", alpha = 0.8)
                                   # or: position = position_dodge(width = NULL)
p <- ggplot(data = df, aes(x = x, y = y, fill = grp, label = grp)) + theme_minimal()
p2 <- p +
  geom_bar(stat = "identity", position = position_dodge(width = NULL)) +
  geom_text(size = 10, position = position_dodge(width = NULL))
                  # or position = "dodge"    

p2
# Warning message:
#  Width not defined. Set with `position_dodge(width = ?)`
ggplot_build(p3)$data[[2]]
#       fill x y label PANEL group xmin xmax ymax colour size angle hjust vjust alpha family fontface lineheight
# 1 #F8766D 1 1     A     1     1    1    1    1  black   10     0   0.5   0.5    NA               1        1.2
# 2 #00BFC4 1 1     B     1     2    1    1    1  black   10     0   0.5   0.5    NA               1        1.2
p2 <- p +
  geom_bar(stat = "identity", position = position_dodge(width = NULL)) +
  geom_text(position = position_dodge(width = 0.9), size = 10)
ggplot_build(p2)$data[[2]]
#      fill     x y label PANEL group xmin xmax ymax colour size angle hjust vjust alpha family fontface lineheight
# 1 #F8766D 0.775 1     A     1     1 0.55 1.00    1  black   10     0   0.5   0.5    NA               1        1.2
# 2 #00BFC4 1.225 1     B     1     2 1.00 1.45    1  black   10     0   0.5   0.5    NA               1        1.2
p2
df <- data.frame(x = rep(c(10, 20, 50), each = 2),
                 y = 1,
                 grp = c("A", "B"))
p <- ggplot(data = df, aes(x = x, y = y, fill = grp, label = grp)) + theme_minimal()

p + 
  geom_bar(stat = "identity", position = position_dodge(width = NULL))
                         # or position = "dodge"
p +
  geom_bar(stat = "identity", position = "dodge") +
  geom_text(position = position_dodge(width = 0.9), size = 10)
resolution(df$x)
# [1] 10
p +
  geom_bar(stat = "identity", position = "dodge") +
  geom_text(position = position_dodge(width = 9), size = 10)
df <- data.frame(x = factor(rep(c(10, 20, 50), each = 2)),
                 y = 1,
                 grp = c("A", "B"))
ggplot(data = df, aes(x = x, y = y, fill = grp, label = grp)) +
  theme_minimal() +
  geom_bar(stat = "identity", position = "dodge") +
  # or: position = position_dodge(width = NULL)
  # or: position = position_dodge(width = 0.9)
  geom_text(position = position_dodge(width = 0.9), size = 10)
ggplot2 position_dodge affects error bar width

ggplot2 position_dodge affects error bar width


By : turan_haldun
Date : March 29 2020, 07:55 AM
this will help As @aosmith suggests, the fix for this is to scale the width of the error bar to the number of points with that x. However, this does not need to be done manually. Below I use dplyr to create a new column in the data.frame based on the number of points at that x. I've also removed the group and fill mappings since neither is needed here (provided the shape is changed to the version of a filled circle coloured by colour rather than fill). Finally, to avoid repetition I've defined the position once and then used a variable for each geom.
code :
library(dplyr)
data <- data %>%
  group_by(x) %>%
  mutate(
    width = 0.1 * n()
  )

pos <- position_dodge(width = 0.2)
myplot <-
  ggplot(data,
         aes(
           x = x,
           y = y,
           colour = treatment,
           width = width
         )) +
  geom_line(size = 1, position = pos) +
  geom_point(size = 3, shape = 16, position = pos) +
  geom_errorbar(aes(ymin = y - se, ymax = y + se), position = pos)

myplot
Related Posts Related Posts :
  • Adding Special Characters to a plot in R
  • How to dynamically change R .libPaths() based on hostname?
  • Print arguments of a function in R
  • Creating Variables via A loop in r
  • How to randomly divide an integer into a fixed number of integers, such that the obtained tuples are uniformly distribut
  • Remove columns using column name based on levels of factors
  • Assigning Dates to Fiscal Year
  • conditional removal from data frame
  • Getting variables out of a function in R
  • Bar colors in ggplot2 geom_bar not applied correctly (R)
  • Create a vector in a dataframe based on matching a second vector to a row name in another object
  • Convert julian day to mm/dd and add year from another column in dataframe in r
  • Change SMOTE parameters inside CARET k-fold cross-validation classification
  • rollapply classes each segment the same
  • rename the header of the spliting group in r
  • Summary stats by factor level for multiple variables
  • Processing Rmarkdown inside chunks
  • R: how to join the duplicate rows in one dataframe
  • Creating a unified time-series, with dates coming from different (natural) languages
  • R error: attempt to apply non-function , randomForest , rfImpute
  • assign multiple color to each vertex in igraph
  • How do I add shading and color to the confidence intervals in ggplot 2 generated Kaplan-Meier plot?
  • How to generate spatial points with a pattern
  • ggplot2 + stat_contour variable binwidth
  • Add fake data to a data frame based on variable condition
  • Utilizing a character vector inside a function
  • match fundction with data frames that are differently constructed
  • Overlaying plots with a horizontal date in R
  • lapply'ing a for loop returns NULL
  • Dynamically add UI elements and gather their input in a dataframe in shiny
  • All the possible outcomes
  • How to Use corrplot with method="number" and Drop Leading Zero?
  • cbind converting factor to numeric
  • create names of loop when iterating data frame
  • R reading multiple raster files gives error in for loop
  • Debugging into and changing R-functions in packages
  • Categorical variables in R - which one does R pick as reference?
  • Create new data frame based on values from another data frame
  • Subplots using Plotly in R (bug fixed)
  • WinBUGS error 'expected key word END' caused by wrong exponential code (not length of data)
  • Predict with gls
  • R list to wide (sparse) data frame
  • Installing ZeligMultilevel. Error : object ‘describe’ is not exported by 'namespace:Zelig'
  • How to use a variable created in a function in your console
  • Dynamic grid plots in shiny R
  • Display unicode in R
  • value of NULL after inserting value
  • Model multiple imputation with interaction terms
  • Dynamically Splitting and naming the dataframe
  • Cross-correlation of 5 time series (distance) and interpretation
  • Grouping columns based on pairwise equality
  • Checking if multiple variables are all the same value in R
  • How to do something to each element in the group
  • R Aggregation on Year based on Time Interval and Key
  • Filling in a new column based on a condition in a data frame
  • Rf_error and Rf_warning definitions
  • R-Programming: Chart the Z distribution of a factor's frequency
  • Split parts of a stacked barplot into individual series
  • Sequentially assign rows of one data frame to empty data frames of varying rows, until all positions within empty data f
  • Using apply to find the optimum of 7 constants?
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co