I'm very new to R and struggling in plotting geom_bar with facet_wrap. I need to manually adding colors to the chart but I can't be able to. I can only add "fill = percentage" to be able to add colors but it's scaled from low to high which I don't want to. I want to manually set two colors
"#554F66", "#C2D1A4" on the chart. The chart only has 2 cols that represent 2 years.
I tried to use scale_fill_manual and scale_color_manual as well but it didn't work. :(
Below are my codes,can you please help? Thank you and much appreciate
ggplot(newdata2,aes(x=as.factor(CODE), y=percentage)) +
geom_bar(stat = "identity", fill = "#554F66")+
facet_wrap(~variable) +
theme_bw() +
xlab("")
it would be very helpful if you could post a reproducible example, with a data set that resembles yours, to help us understand what exactly the problem is.
See some code below that might help you:
ggplot(newdata2,aes(x=as.factor(CODE), y=percentage, fill = percentage)) +
geom_bar(stat = "identity")+
facet_wrap(~variable) +
scale_fill_manual(values = c("#554F66", "#C2D1A4")) +
theme_bw() +
xlab("")
Make sure that you use scale_fill_manual() when using the fill aesthetic.
Related
I'm looking to set up keybindings to increase/decrease gaps and margins in Qtile similar to what the following does in i3-gaps:
bindsym $mod+equal gaps inner current plus 5
bindsym $mod+minus gaps inner current minus 5
bindsym $mod+Shift+equal gaps outer current plus 5
bindsym $mod+Shift+minus gaps outer current minus 5
I can somewhat get the equivalent of outer-gaps to work with the following code:
def increase_gap(qtile):
qtile.screens[0].top.size = screens[0].top.size+5
qtile.screens[0].right.size = screens[0].top.size+5
qtile.screens[0].left.size = screens[0].top.size+5
#margs = screens[0].bottom.margin
screens[0].bottom.margin[0] = screens[0].bottom.margin[0]+5
screens[0].bottom.size=20
qtile.screens[0].cmd_resize()
def decrease_gap(qtile):
qtile.screens[0].top.size = max(screens[0].top.size-5, 0)
qtile.screens[0].right.size = max(screens[0].top.size-5, 0)
qtile.screens[0].left.size = max(screens[0].top.size-5, 0)
#margs = screens[0].bottom.margin
screens[0].bottom.margin[0] = max(screens[0].bottom.margin[0]-5, 0)
screens[0].bottom.size=20
qtile.screens[0].cmd_resize()
Key([mod, "shift"], "equal", lazy.function(increase_gap), desc="Increase gap"),
Key([mod, "shift"], "minus", lazy.function(decrease_gap), desc="Decrease gap"),
I'm not sure this is the right way to do things, though. I'm not sure if this is supposed to be manipulated this way. I'm not really sure that the cmd_resize() function is what I should be using, however from trial and error it's what I've found to work. I'm not sure why the screen[0].bottom.size=20 (20 is the size of my bottom bar. I know I shouldn't hardcode, but I'm trying to produce a proof of concept before I clean the code) is needed, but the bar starts floating if I don't have that there. Finally, increasing and decreasing the gap gets close, but not quite to the original configuration. The gaps look slightly different than the original. So, I'm not sure this is the right way to accomplish this, and I could use the advice.
Secondly, though that gets close to accomplishing what I want on the outer gaps, I have not been able to make any headway to getting the inner gaps to work. I initially tried changing the margin parameter of a layout, and when that didn't work I tried simply initializing a new layout and replacing the old one as posted below, but neither approach worked.
def column_increase_margin(qtile):
current_margin = current_margin + 5
layouts[0] = layout.Columns(border_focus_stack='#d75f5f', margin=current_margin, border_width=0)
screens[0].bottom.size=20
qtile.screens[0].cmd_resize()
I've tried going through the code here, but it's a big project and I'm struggling to make heads or tails from it.
Any advice would be appreciated.
If I understand what you want, you can add the following to the Layout class in libqtile/layout/base.py:
def cmd_increase_margin(self):
self.margin += 10
self.group.layout_all()
def cmd_decrease_margin(self):
new_margin = self.margin - 10
if new_margin < 0:
new_margin = 0
self.margin = new_margin
self.group.layout_all()
You can then add some keys in your config.py to increase and decrease margins. e.g.
KeyChord([mod], "m", [
Key([], "Up", lazy.layout.increase_margin()),
Key([], "Down", lazy.layout.decrease_margin())
],
mode="Margins"
),
I'm new to qtile, so maybe there is something wrong with the above approach, but it seems to work.
I was wondering today about how finding a specific value on a plot and drawing the right line that goes with. I used to do that on an old chart library, and I was wondering that perhaps this functionnality exist but I don't know how to find it.
The result should look like this: https://miro.medium.com/max/1070/1*Ckhi9soE9Lx2lIf9tPVLMQ.png
To provide some context, I'm doing a PCA over my data, and I would like to point out some thresholds at 97.5, 99 and 99.5% of explained cumuled variance.
Have a great day!
EDIT:
See Answer
As solved by ImportanceOfBeingErnest, here is the code:
whole_pca = PCA().fit(np.array(inputs['Scale'].tolist()))
cumul = np.cumsum(np.round(whole_pca.explained_variance_ratio_, decimals=3)*100)
over_95 = np.argmax(cumul>95)
over_99 = np.argmax(cumul>99)
over_995 = np.argmax(cumul>99.5)
plt.plot(cumul)
plt.plot([0,over_95,over_95], [95,95,0])
plt.plot([0,over_99,over_99], [99,99,0])
plt.plot([0,over_995,over_995], [99.5,99.5,0])
plt.xlim(left=0)
plt.ylim(bottom=80)
plt.ylabel('% Variance Explained')
plt.xlabel('# of Features')
plt.title('PCA Analysis')
Result in:
Thank you!
I create 2 Spartials and set one as RigidBodyControl, second as BetterCharacterControl.
Both are boxes of sizes = (10f, 1f, 10f) and (0.5f,0.5f,0.5f).
floor = createFloor();
CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(floor);
landscape = new RigidBodyControl(sceneShape, 0);
floor.addControl(landscape);
rootNode.attachChild(floor);
character = createCharacter();
player = new BetterCharacterControl(1F,1F,0.01f);
character.addControl(player);
rootNode.attachChild(character);
bulletAppState.getPhysicsSpace().add(landscape);
bulletAppState.getPhysicsSpace().add(character);
landscape.setPhysicsLocation(new Vector3f(0,-4,5));
player.warp(new Vector3f(0,0,0));
Now if i run it ... the character just bounces on the floor and i don't know why.
If i use the standard CharacterControl it works, though.
I'am aware that the character box doesn't match the shape but that shouldn't be the problem i guess.
Thanks in advance!
Did you try and turn on debugging?
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
Using debugging could help you see the collision shapes.
thanks for sharing the debug tip.
The problem was:
player = new BetterCharacterControl(1F,1F,0.01f);
You shouldn't create a Cylinder that has a smaller radius than the sizes.
player = new BetterCharacterControl(1F,1F,1F);
worked fine.
In my case, I needed to increase the height of my character by increasing BetterCharacterControl(1.5f, 1f, 1f) to BetterCharacterControl(1.5f, 6f, 1f). I'm not sure why this solved the problem for me, but it did.
I have a figure that I would like to resize and afterwards print as a PDF.
Using something like
set(hFig, 'PaperUnits', 'centimeters')
set(hFig, 'PaperSize', [x_B x_H]);
works as long as I do not resize the figure too drastically. If I reduce the height then at some points the xlabel moves out of the figure. I have searched a lot but only found an solution to manually resize the underlying axes-object
scalefactor = 0.96;
movefactor = 0.82;
hAx = get(gcf,'CurrentAxes');
g = get(hAx,'Position');
% 1=left, 2=bottom, 3=width, 4=height
g(2) = g(2) + (1-movefactor)/2*g(4);
g(4) = scalefactor*g(4);
set(hAx,'Position',g);
I do not like this approach since I have to manually adjust the two factors.
Before printing I set the 'interpreter' to 'latex' of all text-objects (if that is of concern).
Printing is achieved using
print(hFig, '-dpdf', '-loose', 'test.pdf');
I hoped to loosen the bounding box by using '-loose'. Any help is highly appreciated!
edit:
It seems that really the interpreter (none, tex, latex) plays a role in this. I got inspired by this post here (http://stackoverflow.com/questions/5150802/how-to-save-plot-into-pdf-without-large-margin-around) and came up with this solution:
tightInset = get(gca, 'TightInset');
position(1) = tightInset(1);
position(3) = 1 - tightInset(1) - tightInset(3);
if strcmpi(x_Interpreter,'latex')
position(2) = tightInset(2)+ 1*tightInset(4);
position(4) = 1 - tightInset(2) - 2*tightInset(4);
else
position(2) = tightInset(2)+ 0*tightInset(4);
position(4) = 1 - tightInset(2) - 1*tightInset(4);
end
set(gca, 'Position', position);
This may not solve your problem completely (it may just help clean up your code), but I found the fig code in the file exchange to be helpful: it lets you easily set the exact size of figures without bordering white space.
How to show only a fixed number of labels in X-Axis ??
I have tried "LabelSkip", but I think it works only with an interval and not with fixed number of labels.
Here is a print-screen of my chart:
Are you using pChart 1 or pChart2 ?
This can be achived in pChart 1 using setFixedScale
To draw a scale with a maximum value of 10 with 5 points use the following command before drawing the scale
$Graph->setFixedScale(0,10,5);
I know it has been a while since this was asked, but it may help someone:
$maxXLabels = 5; // How many labels on-screen?
$labelSkip = floor( count( $timestamp ) / $maxXLabels ); // how many should we skip?
$myPicture->drawScale(array("LabelSkip"=>$labelSkip));
I have used
"LabelSkip"=>(count($series)/10)
to have 10 labels on the X axis
Works fine for me
Joel Deutscher's answer worked for me. I would have up voted it, but I do not have enough stackoverflow reputation for that.
It works exactly as he said: Chart Width / MinDivHeight = Number of labels on the chart.
Here's my code
$scaleSettings = array("DrawXLines"=>FALSE,"Mode"=>SCALE_MODE_START0,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10,"Pos"=>SCALE_POS_TOPBOTTOM, "MinDivHeight" => 50);
$pchart->chart->drawScale($scaleSettings);