How to change line width in figure legend in julia Plots? - julia

using Plots
plot(1:1:5, 1:1:5, linewidth=1)
plot!(1:1:5, 1:2:10, linewidth=5)
Is it possible to make the legend line width match the line width in the plot? I couldn't find anything in the documentation unfortunately.

Try this out:
using Plots
plot(1:1:5, 1:1:5, linewidth=1)
plot!(1:1:5, 1:2:10, linewidth=5, thickness_scaling = 1)
The resulting output would be the following:

Related

R plot and barplot how to fix ylim not alike?

I try to use base R to plot a time series as a bar plot and as ordinary line plot. I try to write a flexible function to draw such a plot and would like to draw the plots without axes and then add universal axis manually.
Now, I hampered by strange problem: same ylim values result into different axes. Consider the following example:
data(presidents)
# shorten this series a bit
pw <- window(presidents,start=c(1965))
barplot(t(pw),ylim = c(0,80))
par(new=T)
plot(pw,ylim = c(0,80),col="blue",lwd=3)
I intentionally plot y-axes coming from both plots here to show it's not the same. I know I can achieve the intended result by plotting a bar plot first and then add lines using x and y args of lines.
But the I am looking for flexible solution that let's you add lines to barplots like you add lines to points or other line plots. So is there a way to make sure y-axes are the same?
EDIT: also adding the usr parameter to par doesn't help me here.
par(new=T,usr = par("usr"))
Add yaxs="i" to your lineplot. Like this:
plot(pw,ylim = c(0,80),col="blue",lwd=3, yaxs="i")
R start barplots at y=0, while line plots won't. This is to make sure that you see a line if it happens that your data is y=0, otherwise it aligns with the x axis line.

Making symbols bold in ggplot2

I want to use pch=3 in ggplot2 geom_point and I want to make it bold. I can increase the size but could not make it bold. Any suggestions?
libray(ggplot2)
z=data.frame(x=1:12,y=c(3,5,1,6,2,9,7,10,11,4,12,8))
ggplot(z,aes(x=x,y=y))+geom_point(pch=3,size=5)
You can use stroke argument:
library(ggplot2)
z=data.frame(x=1:12,y=c(3,5,1,6,2,9,7,10,11,4,12,8))
ggplot(z,aes(x=x,y=y))+geom_point(pch=3,size=5, stroke = 2)

lattice legend's text position and aligment

I am using lattice package from R. The produced plot has legends, and I want to change the text position of these legends rather than the default (which is always left) to the right position. Example:
As you can see, "Before" the legends produced by lattice like this, whcih I would like to make them like "After".
My trying code:
print(barchart(Value~Topic|Project, d2, groups=Variable, origin=0,
main="Title", auto.key=list(corner = c(0.99, 0.99),points=TRUE,
rectangles=FALSE, background = "gray97" ,
title="Legends", cex=0.8, cex.title=1), xlab="topics",
ylab=expression(paste("Cose(", theta, ")"))) )
You can use key to construct your legend in the order you want. Here is an example drawing the points column before the text column:
library(lattice)
data(Cars93,package="MASS")
labels=levels(Cars93$Cylinders)
xyplot(Price~EngineSize,groups=Cylinders,data=Cars93,
key=list(space="right",adj=0,title="Legends",
points=list(pch=1,
col=trellis.par.get("superpose.symbol")$col[1:length(labels)]),
text=list(labels))
)

Get rid of line beneath bars using hist() in R

I am using the following code if it helpful to plot some data using hist() in R.
hist(info$data, breaks=300, main="Some Data", xlab="data", xlim=c(0, 10000))
And this is the image I get the following image:
Is there a way to get rid of the line at y=0 that is underlining all of the bars? Or is there some better way to extend it to the y axis so it looks more like an axis rather than just some line beneath my bars?
I would use ggplot2
library(ggplot2)
ggplot(info, aes(x=data)) + geom_histogram(binwidth) +
ggtitle("Some Data") + xlab("data") + xlim(0,10000)

resize and adjust the heatmap in heatmap.2

I've generated a heatmap like this:
The X-axis and Y-axis labels don't show completely.
My code is here:
heatmap.2(x,col=blueyelred,colsep=c(1:6),rowsep=(1:62),
sepwidth=c(0.05,0.05), sepcolor="white", trace="none",
Rowv=F,Colv=F, scale="none", dendrogram="none",key=F,
lhei = c(0.05,5),margins=c(1,8))
Is there any way to adjust it.
Thanks!
Cam
A few tips:
to reduce the font size, use the cexRow and cexCol arguments, e.g.
heatmap.2(x, ...., cexRow=0.5)
Adjust the values in the hlei and margins arguments.
I see that you are already using the margins parameter, what if you just modify the arguments as #csgillespie suggested?
e.g., margins = c(8, 8)
Maybe also modifying the general plot margins before calling the heatmap() function could help
e.g., par(mar=c(10,4,4,2))
or for the outer margin
par(oma=c(10,4,4,2))
where
par(mar=c(bottom,left,top,right))

Resources