Note that there are some explanatory texts on larger screens.

plurals
  1. POproblems with ggplot scale, color and linetype parameters
    primarykey
    data
    text
    <p>This is my very first post here, hope I can make myself clear! I am trying to accomplish a very subtle change to my ggplot. I am plotting crosshairs centered on (x,y) with SD showing as errorbars, but the complication i have is with the scale and line types. I have a dataframe (z) where each row is a aggregate over many rows. Each row will be plotted in the ggplot as a crosshair with its own color, however, some rows of the dataframe should be plotted as normal lines, and others should be plotted in dashed lines. Two columns groupnum and groupttl have numeric values for colors and labels respectively that should be shown in the scale, in addition to colors, i also want to show linetype in the scale bar. But I am not able to figure this out yet! </p> <p>Here is what my code is doing: </p> <pre><code>chp &lt;- ggplot(data=z,aes(x=x,y=y,colour = group,group = group,linetype=factor(othr))) + theme_bw() + #remove background xlab(m1) + ylab(m2) + geom_errorbar(aes(ymin = y - ySD, ymax = y + ySD, linetype = factor(othr))) + geom_errorbarh(aes(xmin = x - xSD, xmax = x + xSD, linetype = factor(othr))) + guides(linetype=FALSE) + #remove the legend added by linetype scale_colour_manual(name=hierarchyname, values=factor(unique(groupnum))) + #add colors manually scale_linetype_manual(values = factor(unique(othr))) </code></pre> <p>Note: othr has only two values (1,2) i want to show only two types of lines--normal and dashed.</p> <p>the closest match i found is this: <a href="https://stackoverflow.com/questions/11714564/passing-variable-with-line-types-to-ggplot-linetype">Passing variable with line types to ggplot linetype</a></p> <p>where they say The trick is to use use line_type = geography in conjunction with scale_linetype_manual(values = lty). But in my case, the difference is i don't want each line to have its own linetype, I need only two. </p> <p>I would really appreciate any suggestions on this. Please let me know if you need more info. Thanks SP</p> <hr> <p>Ok. Thanks for suggestions. Here is my dataframe </p> <pre><code>"groupnum","group","N","x","y","xSE","ySE","xSD","ySD","othr" "1",1,"a1",874,9.31080482242276,3.78151559519843,0.000919599013717256,0.0010731700399164,0.803729537988882,0.93795061488693,1 "2",2,"a2",323,9.32858454311781,3.85117814673799,0.00434633223522011,0.00262887468315802,1.4038653119761,0.84912652266004,1 "3",3,"a3",401,8.65698443874862,3.61961141000158,0.00320566652230181,0.0024382624307443,1.28547227544303,0.977743234728466,1 "4",4,"a4",364,8.02722008290545,4.03272290234161,0.00664827121575061,0.00285893561941909,2.41997072253322,1.04065256546855,1 "5",5,"a5",2117,9.38192555351799,3.39287371184691,0.000317738758329197,0.000433382027761261,0.672652951382911,0.917469752770589,1 "6",6,"a6",347,9.2600568761331,3.34027019277033,0.00105036291416114,0.0024058297735207,0.364475931213916,0.834822931411683,1 "7",7,"a7",782,9.26685442279479,3.32913948807558,0.000672770018741615,0.00103475341970955,0.526106154655943,0.809177174212869,1 "8",9,"a8",335,9.33774697202318,3.83086473063289,0.0022406672509349,0.0033135194052142,0.750623529063193,1.11002900074676,1 "9",10,"a9",588,9.2362799520667,3.79905936514298,0.000648139660555769,0.00112763352751969,0.381106120406792,0.663048514181577,1 "10",8,"b1",631,9.39770259697672,3.49584647787853,0.00147287975375933,0.00176346535893738,0.929387124622137,1.11274664148949,2 </code></pre> <p>which can be read using the command <br></p> <pre><code>read.table(file = "zp.txt",sep = ",", header = TRUE, stringsAsFactors = FALSE) </code></pre> <p>Another requirement is: I would like to use <br></p> <pre><code>scale_colour_hue(name=hierarchyname, # Legend label, use darker colors breaks=unique(group), labels=unique(group),#add the legend for all groups l=50, # Use darker colors, lightness=50 c=100) #chroma (intensity of color) </code></pre> <p>instead of scale_colour_manual due to better colors, however, this is a secondary problem, first i want the scale to be fixed! </p> <p>ok was able to edit it too! Thanks SP</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload